Changes between Initial Version and Version 1 of tutorial


Ignore:
Timestamp:
Jun 26, 2013, 9:50:28 PM (11 years ago)
Author:
leon
Comment:

First

Legend:

Unmodified
Added
Removed
Modified
  • tutorial

    v1 v1  
     1= OpenGL tutorial =
     2
     3
     4== Legacy OpenGL ==
     5Create the following {{{first.c}}} using your favourite editor.
     6{{{
     7#!c
     8#include <GL/glut.h>
     9
     10void 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
     21int 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
     32Create {{{Makefile}}} to build your program.
     33
     34{{{
     35#!sh
     36CFLAGS=-Wall
     37LDFLAGS=-lGL -lGLU -lglut -lGLEW
     38
     39ALL=first
     40default: $(ALL)
     41
     42first : first.o
     43
     44clean:
     45      rm -rf *~ *.o $(ALL)
     46}}}
     47Beware that Makefile is TAB aware. So the last line should contain TAB indentation and not spacing.
     48
     49Make and run the program with
     50{{{
     51#!sh
     52make
     53./first
     54}}}
     55
     56Try the same program in Python
     57{{{
     58#!python
     59from OpenGL.GLUT import *
     60from OpenGL.GL import *
     61import sys
     62
     63def 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
     72if __name__ == "__main__":
     73    glutInit(sys.argv)
     74    glutInitDisplayMode(GLUT_DOUBLE)
     75    glutCreateWindow("first.py GL code")
     76    glutDisplayFunc(display)
     77    glutMainLoop()
     78}}}
     79and run it with
     80{{{
     81!sh
     82python first.py
     83}}}
     84
     85