



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An introduction to opengl, a standard library for 2d and 3d drawing. Opengl maps directly to graphics hardware, has a state-based architecture, and uses immediate mode drawing. This guide explains why opengl is used, decodes function names, and covers the structure of an opengl program. It also discusses event-driven interactive programs and the differences between immediate and retained mode rendering.
Typology: Study notes
1 / 5
This page cannot be seen from the preview
Don't miss anything!




Func [234][dfis][v] dimension • example: glVertex3f(x,y,z) — vertex position as 3 floats
v = pass pointer rather than values type (e.g., i=int)
main(){ InitializeApp();while( !done ) {event = WaitForOne();handle(event);}}
void^ on_redraw()
for(all^ triangles
t) draw_triangle(t);}
Retained Mode: void^ initialize(){ load_triangle_list(T);} void^ on_redraw()
//^ red draw_triangle(t2);
//^ red draw_triangle(t3);
//^ red set_color(Blue);draw_triangle(t4);
//^ blue
left ,^ right ,^ bottom
,^ top )
Example: gluOrtho2D(-1, 1, -1, 1)^ -^
OpenGL coordinates
w Window Pixel Coordinatesh (^1) -
r ,^ g ,^ b ,^ α) – specify the color to clear the canvas to– should generally set^ α^ to be 0 (i.e., fully transparent)– this is a state variable, and can be done only once• glClear(GL_COLOR_BUFFER_BIT)– actually clears the screen– there are other things that can be cleared at the same time– such as the depth buffer GL_DEPTH_BUFFER_BIT– but we’re not using it right now And always set the current color before you start drawing^ • for example, glColor3f(0.8, 0.2, 0.2) for a red shade
]^ is the plane normal• hence perpendicular to the triangle• typically use unit normal vector ax^ by^ Normals will show up again and again • especially in rendering cz^ d + + +^ = 0 (^2 2 2) a b c + + = 1
Double Buffering^ • draw in separate frame buffer• front buffer — for video signal• back buffer — drawing target• must redraw entire sceneevery frame• must swap buffers whendrawing is finished• avoids flickering