Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
for dummies…
hello.c
#include <GL/glut.h>
int main(int argc, char** argv)
{ glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (250, 250);
glutInitWindowPosition (100, 100);
glutCreateWindow ("hello");
glClearColor (0.0, 0.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);}
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
void display(void)
{ glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 1.0, 1.0);
glBegin(GL_POLYGON);
glVertex3f (0.25, 0.25, 0.0);
glVertex3f (0.75, 0.25, 0.0);
glVertex3f (0.75, 0.75, 0.0);
glVertex3f (0.25, 0.75, 0.0);
glEnd();
glFlush ();
}
OpenGL’s rendering pipeline
Operations with vertices
Evaluators
Vertex Data Assembling primitives
Fragments operations
Rasterization
Display lists
Frame Buffer
Assembling textures
glutCreateWindow (argv[0]);
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_FLAT);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop(); void display(void){
return 0; glClear (GL_COLOR_BUFFER_BIT);
} glColor3f (1.0, 1.0, 1.0);
glLoadIdentity ();
Viewing gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0,
transformation 0.0, 0.0, 1.0, 0.0);
glScalef (1.0, 2.0, 1.0);
Modeling glutWireCube (1.0);
transformation glFlush ();
}
cube.c
#include <GL/glut.h>
#include <stdlib.h>
int main(int argc, char** argv) Defines left and right clipping planes,
Defines bottom and top clipping planes,
{ glutInit(&argc, argv); Defines zNear and zFar
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (500, 500); This defines a perpective matrix
glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]);
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_FLAT);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0; void reshape (int w, int h){
} glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
Projection glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
transformation glMatrixMode (GL_MODELVIEW);
}
glFrustrum
http://www.meca.ucl.ac.be/~vl/teaching/meca2170/opengl/gl/frustum.html
cube.c
#include <GL/glut.h>
#include <stdlib.h>
{ glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]);
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_FLAT);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}
bezcurve.c
GLfloat ctrlpoints[4][3] = {
{-4.0,-4.0, 0.0}, {-2.0, 4.0, 0.0},
{ 2.0,-4.0, 0.0}, { 4.0, 4.0, 0.0}};
int main(int argc, char** argv)
{ glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]);
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_FLAT);
glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4,
&ctrlpoints[0][0]);
glEnable(GL_MAP1_VERTEX_3);
glutDisplayFunc(display);
glutReshapeFunc(reshape); void reshape(int w, int h)
glutKeyboardFunc(keyboard);
glutMainLoop(); { glViewport(0, 0, (GLsizei) w, (GLsizei) h);
return 0; glMatrixMode(GL_PROJECTION);
} glLoadIdentity();
if (w <= h)
glOrtho(-5.0, 5.0, 5.0*(GLfloat)h/(GLfloat)w,
5.0*(GLfloat)h/(GLfloat)w, -5.0, 5.0);
else
glOrtho(5.0*(GLfloat)w/(GLfloat)h,
5.0*(GLfloat)w/(GLfloat)h,
-5.0, 5.0,-5.0, 5.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
#include <GL/glut.h>
#include <stdlib.h>
GLUnurbsObj *nurb;
GLfloat knots[9] = {-3.0,-2.0,-1.0,0.0,1.0,2.0,3.0,4.0,5.0};
GLfloat ctrlpoints[12][3] = {
{-3.0,-3.0, 0.0},{-1.0, 3.0, 0.0},{ 1.0,-3.0, 0.0},
Et les
{ 3.0, 3.0, 0.0},{-3.0,-4.0, 0.0},{-2.0,-4.0, 0.0},
{-1.0,-4.0, 0.0},{ 0.0,-4.0, 0.0},{ 1.0,-4.0, 0.0},
{ 2.0,-4.0, 0.0},{ 3.0,-4.0, 0.0},{ 4.0,-4.0, 0.0}};
int main(int argc, char** argv)
{ glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
B-splines.
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]);
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_FLAT);
glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4,
&ctrlpoints[0][0]);
glEnable(GL_MAP1_VERTEX_3);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMotionFunc(drag);
glutMainLoop();
return 0;
}
Nurbs = B-splines = Beziers !
Knots, pts de contrôle…
void display(void)
{ glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_LINE_STRIP);
for (i = 0; i <= 30; i++)
glEvalCoord1f((GLfloat) i/30.0);
glEnd();
glPointSize(8.0);
glBegin(GL_POINTS);
for (i = 0; i < 4; i++) {
glColor3f(1.0-0.1*(double)i,1.0-0.1*(double)i,2.0*(double)i);
glVertex3fv(&ctrlpoints[i][0]); }
glEnd();
nurb = gluNewNurbsRenderer();
gluBeginCurve(nurb);
gluNurbsProperty(nurb, GLU_SAMPLING_TOLERANCE, 1.0);
gluNurbsProperty(nurb, GLU_DISPLAY_MODE, GLU_FILL);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_red_diffuse);
gluNurbsCurve(nurb,8,knots,3,&ctrlpoints[0][0],4,GL_MAP1_VERTEX_3);
gluEndCurve(nurb);
glFlush();
}
Joindre deux Nurbs…
nurb = gluNewNurbsRenderer();
gluBeginCurve(nurb);
gluNurbsProperty(nurb, GLU_SAMPLING_TOLERANCE, 1.0);
gluNurbsProperty(nurb, GLU_DISPLAY_MODE, GLU_FILL);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_red_diffuse);
gluNurbsCurve(nurb,8,&knots[0],3,&ctrlpoints[0][0],4,GL_MAP1_VERTEX_3);
gluEndCurve(nurb);
glColor3f(1.0,0.0,0.0);
nurb = gluNewNurbsRenderer();
gluNurbsProperty(nurb, GLU_SAMPLING_TOLERANCE, 1.0);
gluNurbsProperty(nurb, GLU_DISPLAY_MODE, GLU_FILL);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_red_diffuse);
gluBeginCurve(nurb);
gluNurbsCurve(nurb,8,&knots[1],3,&ctrlpoints[1][0],4,GL_MAP1_VERTEX_3);
gluEndCurve(nurb);
Ce qui vous sera
demandé en 07-08
http://www.mema.ucl.ac.be/~comblen/meca2170/