Create a new lab09 project as usual.
Use the following setRC:
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glColor3f(0.0f, 1.0f, 0.0f);
glOrtho (-100.0f, 100.0f, -100.0f, 100.0f, -100.0f, 100.0f);
glPolygonMode(GL_FRONT,GL_LINE);
glPolygonMode(GL_BACK, GL_LINE);
glShadeModel(GL_FLAT);
glEnable(GL_DEPTH_TEST);
void drawQuad()
{
glBegin(GL_QUADS);
glVertex3f(-50.0f, 0.0f, 0.0f);
glVertex3f( 0.0f, 50.0f, 0.0f);
glVertex3f( 50.0f, 0.0f, 0.0f);
glVertex3f( 0.0f, -50.0f, 0.0f);
glEnd();
}
void drawQuadStrips()
{
glBegin(GL_QUAD_STRIP);
glVertex3f(-50.0f, -50.0f, 0.0f);
glVertex3f( -50.0f, 50.0f, 0.0f);
glVertex3f( 0.0f, -50.0f, 0.0f);
glVertex3f( 0.0f, 50.0f, 0.0f);
glVertex3f( 50.0f, -50.0f, 0.0f);
glVertex3f( 50.0f, 50.0f, 0.0f);
glEnd();
}
void drawPolygon()
{
glBegin(GL_POLYGON);
glVertex3f(-50.0f, 50.0f, 0.0f);
glVertex3f( 20.0f, 50.0f, 0.0f);
glVertex3f( 50.0f, 30.0f, 0.0f);
glVertex3f( 50.0f, -50.0f, 0.0f);
glVertex3f(-50.0f, -50.0f, 0.0f);
glEnd();
}
void star()
{
glBegin(GL_TRIANGLES);
glVertex2f(-20.0f, 0.0f);
glVertex2f(20.0f, 0.0f);
glVertex2f(0.0f, 40.0f);
glVertex2f(-20.0f,0.0f);
glVertex2f(-60.0f,-20.0f);
glVertex2f(-20.0f,-40.0f);
glVertex2f(-20.0f,-40.0f);
glVertex2f(0.0f, -80.0f);
glVertex2f(20.0f, -40.0f);
glVertex2f(20.0f, -40.0f);
glVertex2f(60.0f, -20.0f);
glVertex2f(20.0f, 0.0f);
glVertex2f(-20.0f, 0.0f);
glVertex2f(-20.0f,-40.0f);
glVertex2f(20.0f, 0.0f);
glVertex2f(-20.0f,-40.0f);
glVertex2f(20.0f, -40.0f);
glVertex2f(20.0f, 0.0f);
glEnd();
}
glPolygonMode(GL_FRONT,GL_FILL);
glPolygonMode(GL_BACK, GL_FILL);
As you can see, the edges are showing. Wether these edges are displayed or not can be controlled by this api call:
Try this version:
void starWithoutEdges()
{
glBegin(GL_TRIANGLES);
glEdgeFlag(GL_FALSE);
glVertex2f(-20.0f, 0.0f);
glEdgeFlag(GL_TRUE);
glVertex2f(20.0f, 0.0f);
glVertex2f(0.0f, 40.0f);
glVertex2f(-20.0f,0.0f);
glVertex2f(-60.0f,-20.0f);
glEdgeFlag(GL_FALSE);
glVertex2f(-20.0f,-40.0f);
glEdgeFlag(GL_TRUE);
glVertex2f(-20.0f,-40.0f);
glVertex2f(0.0f, -80.0f);
glEdgeFlag(GL_FALSE);
glVertex2f(20.0f, -40.0f);
glEdgeFlag(GL_TRUE);
glVertex2f(20.0f, -40.0f);
glVertex2f(60.0f, -20.0f);
glEdgeFlag(GL_FALSE);
glVertex2f(20.0f, 0.0f);
glEdgeFlag(GL_TRUE);
glEdgeFlag(GL_FALSE);
glVertex2f(-20.0f, 0.0f);
glVertex2f(-20.0f,-40.0f);
glVertex2f(20.0f, 0.0f);
glVertex2f(-20.0f,-40.0f);
glVertex2f(20.0f, -40.0f);
glVertex2f(20.0f, 0.0f);
glEdgeFlag(GL_TRUE);
glEnd();
}
So far your application have been single buffered.
This is configured in main with GLUT_SINGLE
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
void renderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
starWithoutEdges();
glFlush();
}
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
and using this methdod:
instead of
This would be the default for many applications.
In some circumstances you may require single buffering.
Review the glScissor
Rework the rendering in this lab to only render the a rectangular portion of the screen.