| 1 | = OpenGL tutorial = |
| 2 | |
| 3 | |
| 4 | == Legacy OpenGL == |
| 5 | Create the following {{{first.c}}} using your favourite editor. |
| 6 | {{{ |
| 7 | #!c |
| 8 | #include <GL/glut.h> |
| 9 | |
| 10 | void display() |
| 11 | { |
| 12 | glClear(GL_COLOR_BUFFER_BIT); |
| 13 | glColor3f(1.0, 0.4, 1.0); |
| 14 | glBegin(GL_LINES); |
| 15 | glVertex2f(0.1, 0.1); |
| 16 | glVertex3f(0.8, 0.8, 1.0); |
| 17 | glEnd(); |
| 18 | glutSwapBuffers(); |
| 19 | } |
| 20 | |
| 21 | int main(int argc, char *argv[]) |
| 22 | { |
| 23 | glutInit(&argc,argv); |
| 24 | glutInitDisplayMode(GLUT_DOUBLE); |
| 25 | glutCreateWindow("first.c GL code"); |
| 26 | glutDisplayFunc(display); |
| 27 | glutMainLoop(); |
| 28 | return 0; |
| 29 | } |
| 30 | }}} |
| 31 | |
| 32 | Create {{{Makefile}}} to build your program. |
| 33 | |
| 34 | {{{ |
| 35 | #!sh |
| 36 | CFLAGS=-Wall |
| 37 | LDFLAGS=-lGL -lGLU -lglut -lGLEW |
| 38 | |
| 39 | ALL=first |
| 40 | default: $(ALL) |
| 41 | |
| 42 | first : first.o |
| 43 | |
| 44 | clean: |
| 45 | rm -rf *~ *.o $(ALL) |
| 46 | }}} |
| 47 | Beware that Makefile is TAB aware. So the last line should contain TAB indentation and not spacing. |
| 48 | |
| 49 | Make and run the program with |
| 50 | {{{ |
| 51 | #!sh |
| 52 | make |
| 53 | ./first |
| 54 | }}} |
| 55 | |
| 56 | Try the same program in Python |
| 57 | {{{ |
| 58 | #!python |
| 59 | from OpenGL.GLUT import * |
| 60 | from OpenGL.GL import * |
| 61 | import sys |
| 62 | |
| 63 | def display(): |
| 64 | glClear(GL_COLOR_BUFFER_BIT) |
| 65 | glColor3f(1.0, 0.4, 1.0) |
| 66 | glBegin(GL_LINES) |
| 67 | glVertex2f(0.1, 0.1) |
| 68 | glVertex3f(0.8, 0.8, 1.0) |
| 69 | glEnd() |
| 70 | glutSwapBuffers() |
| 71 | |
| 72 | if __name__ == "__main__": |
| 73 | glutInit(sys.argv) |
| 74 | glutInitDisplayMode(GLUT_DOUBLE) |
| 75 | glutCreateWindow("first.py GL code") |
| 76 | glutDisplayFunc(display) |
| 77 | glutMainLoop() |
| 78 | }}} |
| 79 | and run it with |
| 80 | {{{ |
| 81 | !sh |
| 82 | python first.py |
| 83 | }}} |
| 84 | |
| 85 | |