This lab sheet aims to teach students how to draw 2D graphics using OpenGL. It provides two tasks for students to complete: 1) Write and run a simple program to draw a square polygon using OpenGL functions like glBegin, glVertex2f, and glEnd. 2) Write and run a more advanced program that uses functions like glGenLists, glNewList, glCallList, glAccum to draw two colored rectangles and apply accumulation buffering. The objectives are for students to learn how to draw basic 2D graphics and use additional OpenGL features like display lists and accumulation buffering.
This lab sheet aims to teach students how to draw 2D graphics using OpenGL. It provides two tasks for students to complete: 1) Write and run a simple program to draw a square polygon using OpenGL functions like glBegin, glVertex2f, and glEnd. 2) Write and run a more advanced program that uses functions like glGenLists, glNewList, glCallList, glAccum to draw two colored rectangles and apply accumulation buffering. The objectives are for students to learn how to draw basic 2D graphics and use additional OpenGL features like display lists and accumulation buffering.
This lab sheet aims to teach students how to draw 2D graphics using OpenGL. It provides two tasks for students to complete: 1) Write and run a simple program to draw a square polygon using OpenGL functions like glBegin, glVertex2f, and glEnd. 2) Write and run a more advanced program that uses functions like glGenLists, glNewList, glCallList, glAccum to draw two colored rectangles and apply accumulation buffering. The objectives are for students to learn how to draw basic 2D graphics and use additional OpenGL features like display lists and accumulation buffering.
Faculty of Computer Science and Information Technology
BIT2023/BIT20203: Graphics Programming LAB SHEET 2 Title Objectives
: Graphics Programming using OpenGL
: At the end of the session, students are able to: i. Draw a simple 2D graphics using OpenGL.
Duration Tasks
: 2 Hours :
1. Write the following code. Compile and run.
#include <GL/glut.h> void display(void) { /* clear window */ glClear(GL_COLOR_BUFFER_BIT); /* draw unit square polygon */ glBegin(GL_POLYGON); glVertex2f(-0.5, -0.5); glVertex2f(-0.5, 0.5); glVertex2f(0.5, 0.5); glVertex2f(0.5, -0.5); glEnd(); /* flush GL buffers */ glFlush(); } void init() { /* set clear color to black */ /* glClearColor (0.0, 0.0, 0.0, 0.0); */ /* set fill color to white */ /*
glColor3f(1.0, 1.0, 1.0); */
/* set up standard orthogonal view with clipping */
/* box as cube of side 2 centered at origin */ /* This is default view and these statement could be removed */ /* glMatrixMode (GL_PROJECTION); glLoadIdentity (); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); } mni\teaching\20092010\s1\bit2023\
*/
Universiti Tun Hussein Onn Malaysia
Faculty of Computer Science and Information Technology int main(int argc, char** argv) { /* Initialize mode and open a window in upper left corner of screen */ /* Window title is name of program (arg[0]) */ /* You must call glutInit before any other OpenGL/GLUT calls */ glutInit(&argc,argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(500,500); glutInitWindowPosition(0,0); glutCreateWindow("simple"); glutDisplayFunc(display); init(); glutMainLoop(); return 0; }