Changing background color by button press in GLUT - opengl

been following a few tutorials and other questions people have been asking on here. Essentially trying to make it when you press the escape key the background colour changes into another colour.
Edited the post with the whole code.
#include "stdafx.h"
#include <glut.h>
void render(void);
void keyboard(int key, int x, int y);
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100, 100); //Position of the window
glutInitWindowSize(620, 440); //Screen Size
glClearColor (0.0, 1.0, 0.0, 0.0 );
glutCreateWindow("Greeting Card"); //Creates the window and names it
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Enables Alpha channel
glutDisplayFunc(render);
glutDisplayFunc(draw);
glutKeyboardFunc(keyboard);
glutMainLoop(); //Finished, now render
}
void keyboard (unsigned char key, int x, int y)
{
GLfloat colors[][3] = { { 0.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 0.0f } };
static int back;
switch (key) {
case 27:
exit(0);
default:
back ^= 1;
glClearColor(colors[back][0], colors[back][1], colors[back][2], 1.0f);
glutPostRedisplay();
}
}
void render(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// World Snow //
glPushMatrix();
glTranslatef(0, -0.35, 0); //Position of the shape
glBegin(GL_POLYGON); //Defines the type of shape
glColor3f(1, 1,1); //Colour of the shape 'RED, GREEN, BLUE'
glVertex2f(-1.5,-0.7); //Vertex 2F Gives the vertex some coords
glColor3f(1, 1, 1);
glVertex2f(-1.5, 0.7);
glColor3f(1, 1, 1);
glVertex2f( 1.5, 0.7);
glColor3f(1, 1, 1);
glVertex2f( 1.5,-0.7);
glEnd();
glPopMatrix();
glFlush();
// Grey gradient world
glPushMatrix();
glTranslatef(0, -0.35, 0);
glBegin(GL_POLYGON);
glColor3f(1, 1, 1);
glVertex2f(-1.5,-0.7);
glColor3f(1, 1, 1);
glVertex2f(-1.5, 0.7);
glColor3f(0.658824, 0.658824, 0.658824);
glVertex2f( 1.5, 0.7);
glColor3f(1, 1, 1);
glVertex2f( 1.5,-1.7);
glEnd();
glPopMatrix();
glFlush();
// Top of the first Tree //
glPushMatrix();
glTranslatef(-0.6, 0.5, 0);
glBegin(GL_TRIANGLES); //Defines the shape as being a triangle
glColor3f( 0.137255, 0.556863,0.137255);
glVertex2f(-0.1, -0.1);
glColor3f( 0.137255, 0.556863,0.137255);
glVertex2f(0.1, -0.1);
glColor3f( 0.137255, 0.556863,0.137255);
glVertex2f(0.0, 0.1);
glEnd();
glPopMatrix();
// Middle of the first tree
glPushMatrix();
glTranslatef(-0.6, 0.4, 0);
glBegin(GL_TRIANGLES);
glColor3f( 0.137255, 0.556863,0.137255);
glVertex2f(-0.1, -0.1);
glColor3f( 0.137255, 0.556863,0.137255);
glVertex2f(0.1, -0.1);
glColor3f( 0.137255, 0.556863,0.137255);
glVertex2f(0.0, 0.1);
glEnd();
glPopMatrix();
// Bottom of the first tree
glPushMatrix();
glTranslatef(-0.6, 0.3, 0);
glBegin(GL_TRIANGLES);
glColor3f( 0.137255, 0.556863,0.137255);
glVertex2f(-0.1, -0.1);
glColor3f( 0.137255, 0.556863,0.137255);
glVertex2f(0.1, -0.1);
glColor3f( 0.137255, 0.556863,0.137255);
glVertex2f(0.0, 0.1);
glEnd();
glPopMatrix();
glFlush();
//Stump of first tree
glPushMatrix();
glTranslatef(-0.6, 0.16, 0);
glBegin(GL_POLYGON);
glColor3f( 0.36, 0.25, 0.20);
glVertex2f(-0.02,-0.04);
glColor3f( 0.36, 0.25, 0.20);
glVertex2f(-0.02, 0.04);
glColor3f( 0.647059, 0.164706, 0.164706);
glVertex2f( 0.02, 0.04);
glColor3f( 0.36, 0.25, 0.20);
glVertex2f( 0.02,-0.04);
glEnd();
glPopMatrix();
// Large Tree TOP
glPushMatrix();
glTranslatef(-0.2, 0, 0);
glBegin(GL_TRIANGLES);
glColor3f( 0.137255, 0.556863,0.137255);
glVertex2f(-0.15, -0.15);
glColor3f( 0.137255, 0.556863,0.137255);
glVertex2f(0.15, -0.15);
glColor3f( 0.137255, 0.556863,0.137255);
glVertex2f(0.0, 0.15);
glEnd();
glPopMatrix();
glFlush();
//Large Tree MIDDLE
glPushMatrix();
glTranslatef(-0.2, -0.15, 0);
glBegin(GL_TRIANGLES);
glColor3f( 0.137255, 0.556863,0.137255);
glVertex2f(-0.15, -0.15);
glColor3f( 0.137255, 0.556863,0.137255);;
glVertex2f(0.15, -0.15);
glColor3f( 0.137255, 0.556863,0.137255);
glVertex2f(0.0, 0.15);
glEnd();
glPopMatrix();
glFlush();
//Large Tree Bottom
glPushMatrix();
glTranslatef(-0.2, -0.30, 0);
glBegin(GL_TRIANGLES);
glColor3f( 0.137255, 0.556863,0.137255);
glVertex2f(-0.15, -0.15);
glColor3f( 0.137255, 0.556863,0.137255);
glVertex2f(0.15, -0.15);
glColor3f( 0.137255, 0.556863,0.137255);
glVertex2f(0.0, 0.15);
glEnd();
glPopMatrix();
glFlush();
//Smaller tree Top
glPushMatrix();
glTranslatef(0.05, 0.45, 0);
glBegin(GL_TRIANGLES);
glColor3f( 0.137255, 0.556863,0.137255);
glVertex2f(-0.05, -0.05);
glColor3f( 0.137255, 0.556863,0.137255);
glVertex2f(0.05, -0.05);
glColor3f( 0.137255, 0.556863,0.137255);
glVertex2f(0.0, 0.05);
glEnd();
glPopMatrix();
glFlush();
//Smaller tree MIDDLE
glPushMatrix();
glTranslatef(0.05, 0.40, 0);
glBegin(GL_TRIANGLES);
glColor3f( 0.137255, 0.556863,0.137255);
glVertex2f(-0.05, -0.05);
glColor3f( 0.137255, 0.556863,0.137255);
glVertex2f(0.05, -0.05);
glColor3f( 0.137255, 0.556863,0.137255);
glVertex2f(0.0, 0.05);
glEnd();
glPopMatrix();
glFlush();
//smaller tree bottom
glPushMatrix();
glTranslatef(0.05, 0.50, 0);
glBegin(GL_TRIANGLES);
glColor3f( 0.137255, 0.556863,0.137255);
glVertex2f(-0.05, -0.05);
glColor3f( 0.137255, 0.556863,0.137255);
glVertex2f(0.05, -0.05);
glColor3f(0.32, 0.49, 0.46);
glVertex2f(0.0, 0.05);
glEnd();
glPopMatrix();
glFlush();
//Stump of smaller tree
glPushMatrix();
glTranslatef(0.05, 0.32, 0);
glBegin(GL_POLYGON);
glColor3f( 0.36, 0.25, 0.20);
glVertex2f(-0.01,-0.03);
glColor3f( 0.36, 0.25, 0.20);
glVertex2f(-0.01, 0.03);
glColor3f( 0.647059, 0.164706, 0.164706);
glVertex2f( 0.01, 0.03);
glColor3f( 0.36, 0.25, 0.20);
glVertex2f( 0.01,-0.03);
glEnd();
glPopMatrix();
//Stump of MAIN tree
glPushMatrix();
glTranslatef(-0.2, -0.50, 0);
glBegin(GL_POLYGON);
glColor3f( 0.36, 0.25, 0.20);
glVertex2f(-0.02,-0.05);
glColor3f( 0.36, 0.25, 0.20);
glVertex2f(-0.02, 0.05);
glColor3f( 0.647059, 0.164706, 0.164706);
glVertex2f( 0.02, 0.05);
glColor3f( 0.36, 0.25, 0.20);
glVertex2f( 0.02,-0.05);
glEnd();
glPopMatrix();
// Red Present
glPushMatrix();
glTranslatef(0, -0.5, 0);
glBegin(GL_POLYGON);
glColor3f( 1, 0, 1);
glVertex2f(-0.04,-0.05);
glColor3f( 1, 0, 0);
glVertex2f(-0.04, 0.05);
glColor3f( 1, 0, 0);
glVertex2f( 0.04, 0.05);
glColor3f( 1, 0, 0);
glVertex2f( 0.04,-0.05);
glEnd();
glPopMatrix();
//Blue Present
glPushMatrix();
glTranslatef(-0.2, -0.7, 0);
glBegin(GL_POLYGON);
glColor3f( 0, 0, 1);
glVertex2f(-0.07,-0.06);
glColor3f( 0, 0, 1);
glVertex2f(-0.07, 0.06);
glColor3f( 0, 0, 1);
glVertex2f( 0.07, 0.06);
glColor3f( 0.196078, 0.6, 0.8);
glVertex2f( 0.07,-0.06);
glEnd();
glPopMatrix();
// BLUE Ribbon RED present VERT
glPushMatrix();
glTranslatef(0, -0.5, 0);
glBegin(GL_POLYGON);
glColor3f( 0, 0, 1);
glVertex2f(-0.04,-0.01);
glColor3f( 0, 0, 1);
glVertex2f(-0.04, 0.01);
glColor3f( 0, 0, 1);
glVertex2f( 0.04, 0.01);
glColor3f( 0, 0, 1);
glVertex2f( 0.04,-0.01);
glEnd();
glPopMatrix();
//BLUE ribbon RED present HORIZ
glPushMatrix();
glTranslatef(0, -0.5, 0);
glBegin(GL_POLYGON);
glColor3f( 0, 0, 1);
glVertex2f(-0.01,-0.05);
glColor3f( 0, 0, 1);
glVertex2f(-0.01, 0.05);
glColor3f( 0, 0, 1);
glVertex2f( 0.01, 0.05);
glColor3f( 0, 0, 1);
glVertex2f( 0.01,-0.05);
glEnd();
glPopMatrix();
//Yellow Ribbon Blue Present VERT
glPushMatrix();
glTranslatef(-0.2, -0.7, 0);
glBegin(GL_POLYGON);
glColor3f( 0.6, 0.8, 0.196078);
glVertex2f(-0.07,-0.01);
glColor3f( 0.6, 0.8, 0.196078);
glVertex2f(-0.07, 0.01);
glColor3f( 0.6, 0.8, 0.196078);
glVertex2f( 0.07, 0.01);
glColor3f( 0.6, 0.8, 0.196078);
glVertex2f( 0.07,-0.01);
glEnd();
glPopMatrix();
// BLUE present YELLOW ribbon VERT
glPushMatrix();
glTranslatef(-0.2, -0.7, 0);
glBegin(GL_POLYGON);
glColor3f( 0.6, 0.8, 0.196078);
glVertex2f(-0.01,-0.06);
glColor3f( 0.6, 0.8, 0.196078);
glVertex2f(-0.01, 0.06);
glColor3f( 0.6, 0.8, 0.196078);
glVertex2f( 0.01, 0.06);
glColor3f( 0.6, 0.8, 0.196078);
glVertex2f( 0.01,-0.06);
glEnd();
glPopMatrix();
//Sign Post
glPushMatrix();
glTranslatef(0.5, -0.1, 0);
glBegin(GL_POLYGON);
glColor3f( 0.36, 0.25, 0.20);
glVertex2f(-0.02,-0.25);
glColor3f( 0.36, 0.25, 0.20);
glVertex2f(-0.02, 0.25);
glColor3f( 0.35, 0.16, 0.14);
glVertex2f( 0.02, 0.25);
glColor3f( 0.36, 0.25, 0.20);
glVertex2f( 0.02,-0.25);
glEnd();
glPopMatrix();
//Sign, Attatched to the post
glPushMatrix();
glTranslatef(0.5, -0.001, 0);
glBegin(GL_POLYGON);
glColor3f( 0.36, 0.25, 0.20);
glVertex2f(-0.15,-0.10);
glColor3f( 0.36, 0.25, 0.20);
glVertex2f(-0.15, 0.10);
glColor3f( 0.35, 0.16, 0.14);
glVertex2f( 0.15, 0.10);
glColor3f( 0.36, 0.25, 0.20);
glVertex2f( 0.15,-0.10);
glEnd();
glPopMatrix();
//Moon
glPushMatrix();
glTranslatef(-0.9, 0.90, 0);
glBegin(GL_POLYGON);
glColor4f( 0.90, 0.91, 0.98, 1); //RGBA
glVertex2f(-0.10,-0.2);
glColor4f( 0.329412, 0.329412, 0.329412, 1);
glVertex2f(-0.10, 0.2);
glColor4f( 0.90, 0.91, 0.98, 1);
glVertex2f( 0.10, 0.2);
glColor4f( 0.90, 0.91, 0.98, 1);
glVertex2f( 0.10,-0.2);
glEnd();
glPopMatrix();
//MAIN PRESENT UNDER SIGN
glPushMatrix();
glTranslatef(0.5, -0.6, 0);
glBegin(GL_POLYGON);
glColor3f( 0.89, 0.47, 0.20);
glVertex2f(-0.20,-0.20);
glColor3f( 0.89, 0.47, 0.20);
glVertex2f(-0.20, 0.20);
glColor3f( 0.89, 0.47, 0.20);
glVertex2f( 0.20, 0.20);
glColor3f( 1.0, 0.25, 0);
glVertex2f( 0.20,-0.20);
glEnd();
glPopMatrix();
//Orange Present Purple Ribbon VERT
glPushMatrix();
glTranslatef(0.5, -0.6, 0);
glBegin(GL_POLYGON);
glColor3f( 0.73, 0.16, 0.96);
glVertex2f(-0.20,-0.06);
glColor3f( 0.73, 0.16, 0.96);
glVertex2f(-0.20, 0.06);
glColor3f( 0.87, 0.58, 0.98);
glVertex2f( 0.20, 0.06);
glColor3f( 0.87, 0.58, 0.98);
glVertex2f( 0.20,-0.06);
glEnd();
glPopMatrix();
//Orange Present Purple Ribbon HORIZ
glTranslatef(0.5, -0.6, 0);
glBegin(GL_POLYGON);
glColor3f( 0.87, 0.58, 0.98);
glVertex2f(-0.06,-0.20);
glColor3f( 0.87, 0.58, 0.98);
glVertex2f(-0.06, 0.20);
glColor3f( 0.73, 0.16, 0.96);
glVertex2f( 0.06, 0.20);
glColor3f( 0.73, 0.16, 0.96);
glVertex2f( 0.06,-0.20);
glEnd();
glPopMatrix();
glFlush();
//'North Pole' TEXT sign
glPushMatrix();
glLoadIdentity();
glTranslatef(0.360, -0.010, 0);
glRotatef(90,0.0f,0.0f,0.0f);
glColor3f( 0.0, 0.0, 0.0 ); //Colour is black
glRasterPos3i(10,100,1);
char text[50]="North Pole"; //Text
for(int i=0; i<50; i++)
{
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,(int)text[i]);
}
glPopMatrix();
glutSwapBuffers();
}

trying to make it when you press the escape key the background colour changes into another colour.
Then why are you exit()ing when you press it? Swap your case 27: and default: logic.
Reset your projection/modelview matrices each time through render():
void render()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
...
You also have an un-matched glPopMatrix() in "Orange Present Purple Ribbon HORIZ":
//Orange Present Purple Ribbon HORIZ
glTranslatef(0.5, -0.6, 0);
glBegin(GL_POLYGON);
glColor3f( 0.87, 0.58, 0.98);
glVertex2f(-0.06,-0.20);
glColor3f( 0.87, 0.58, 0.98);
glVertex2f(-0.06, 0.20);
glColor3f( 0.73, 0.16, 0.96);
glVertex2f( 0.06, 0.20);
glColor3f( 0.73, 0.16, 0.96);
glVertex2f( 0.06,-0.20);
glEnd();
glPopMatrix();
^^^^^^^^^^^^^ wha-hey?
Other than those things the background toggle seems to work.

Related

glPushMatrix() glPopMatrix() doesn't work

I try to code two object move independent which mean both are moving two different direction it's worked but it can't move continuous. when i put glTranslatef() at outside the glPushMatrix() ... glPopMatrix() it work normally.
void display()
{
glClearColor(0.356, 0.701, 0.0, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
// if put gltransate() at here the object will moving continuous
glPushMatrix();
glTranslatef(.5, 0, 0);
glBegin(GL_QUADS);
glColor3f(1.0, 1.0, 1.0);
glVertex2f(-0.8, 0.5);
glVertex2f(-0.8, 0.8);
glVertex2f(-0.2, 0.8);
glVertex2f(-0.2, 0.5);
glEnd();
glPopMatrix();
glPushMatrix();
glTranslatef(-.5, 0, 0);
glBegin(GL_QUADS);
glColor3f(.0, .0, .0);
glVertex2f(-0.8, 0.2);
glVertex2f(-0.8, 0.5);
glVertex2f(-0.2, 0.5);
glVertex2f(-0.2, 0.2);
glEnd();
glPopMatrix();
}
i expect the for the first square objects will go to the right constantly but it seem like just translate once then stop at the position.
Note, in general I recommend to use a math library like OpenGL Mathematics to do the matrix calculations and glLoadMatrix() to load a matrix of type glm::mat4 to the current matrix.
Anyway, an operation like glTranslatef() creates a new matrix and multiplies the current matrix by the new matrix. That's why consecutive calls to glTranslatef cause progressive "movement".
glPushMatrix / glPopMatrix store and restore the matrix on the matrix stack. So the consecutive movement can't work, because the current matrix stays the same at the begin of each frame.
One solution would be to store the translation to a variable and increment the variable:
GLfloat trans_a = 0.0f;
GLflaot trans_b = 0.0f;
void display()
{
glClearColor(0.356, 0.701, 0.0, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
trans_a += 0.5f;
glTranslatef(trans_a, 0, 0);
glBegin(GL_QUADS);
glColor3f(1.0, 1.0, 1.0);
glVertex2f(-0.8, 0.5);
glVertex2f(-0.8, 0.8);
glVertex2f(-0.2, 0.8);
glVertex2f(-0.2, 0.5);
glEnd();
glPopMatrix();
glPushMatrix();
trans_b += 0.5f;
glTranslatef(trans_b, 0, 0);
glBegin(GL_QUADS);
glColor3f(.0, .0, .0);
glVertex2f(-0.8, 0.2);
glVertex2f(-0.8, 0.5);
glVertex2f(-0.2, 0.5);
glVertex2f(-0.2, 0.2);
glEnd();
glPopMatrix();
}
A more generalized solution is to get and store the current matrix (after the translation) by glGetFloatv(GL_MODELVIEW_MATRIX, ...) and to reload it by glLoadMatrix():
// init identity matrices
GLfloat mat_a[16] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
GLfloat mat_b[16] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
void display()
{
glClearColor(0.356, 0.701, 0.0, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glLoadMatrixf(mat_a)
glTranslatef(0.5f, 0, 0);
glGetFloatv(GL_MODELVIEW_MATRIX, mat_a);
glBegin(GL_QUADS);
glColor3f(1.0, 1.0, 1.0);
glVertex2f(-0.8, 0.5);
glVertex2f(-0.8, 0.8);
glVertex2f(-0.2, 0.8);
glVertex2f(-0.2, 0.5);
glEnd();
glPopMatrix();
glPushMatrix();
glLoadMatrixf(mat_b)
glTranslatef(0.5f, 0, 0);
glGetFloatv(GL_MODELVIEW_MATRIX, mat_b);
glBegin(GL_QUADS);
glColor3f(.0, .0, .0);
glVertex2f(-0.8, 0.2);
glVertex2f(-0.8, 0.5);
glVertex2f(-0.2, 0.5);
glVertex2f(-0.2, 0.2);
glEnd();
glPopMatrix();
}
Note, in this case mat_a and mat_b should be loaded after the initialization of the view matrix and when the view matrix changes, then the matrices would not consider that.

OpenGL rendering causes graphical glitch

Code is below. When the program runs, it generates a more or less correct image, but there are some graphical glitches. Here are some images:. Any ideas on what could be causing this? The weirdest part is that the issue appears to form on triangles, even though the image is being drawn with polygons (quads).
void buildList() {
cubelist = glGenLists(1);
glNewList(cubelist,GL_COMPILE);
// Multi-colored side - FRONT
glBegin(GL_POLYGON);
glColor3b(0,0,0);
glVertex3f( -0.5, -0.5, -0.5);
glVertex3f( -0.5, 0.5, -0.5);
glVertex3f( 0.5, 0.5, -0.5);
glVertex3f( 0.5, -0.5, -0.5);
// Black side - BACK
glBegin(GL_POLYGON);
glColor3b(0,0,0);
glVertex3f( 0.5, -0.5, 0.5 );
glVertex3f( 0.5, 0.5, 0.5 );
glVertex3f( -0.5, 0.5, 0.5 );
glVertex3f( -0.5, -0.5, 0.5 );
glEnd();
// Purple side - RIGHT
glBegin(GL_POLYGON);
glColor3f( 1.0, 0.0, 1.0 );
glVertex3f( 0.5, -0.5, -0.5 );
glVertex3f( 0.5, 0.5, -0.5 );
glVertex3f( 0.5, 0.5, 0.5 );
glVertex3f( 0.5, -0.5, 0.5 );
glEnd();
// Green side - LEFT
glBegin(GL_POLYGON);
glColor3f( 0.0, 1.0, 0.0 );
glVertex3f( -0.5, -0.5, 0.5 );
glVertex3f( -0.5, 0.5, 0.5 );
glVertex3f( -0.5, 0.5, -0.5 );
glVertex3f( -0.5, -0.5, -0.5 );
glEnd();
// Blue side - TOP
glBegin(GL_POLYGON);
glColor3f( 0.0, 0.0, 1.0 );
glVertex3f( 0.5, 0.5, 0.5 );
glVertex3f( 0.5, 0.5, -0.5 );
glVertex3f( -0.5, 0.5, -0.5 );
glVertex3f( -0.5, 0.5, 0.5 );
glEnd();
// Red side - BOTTOM
glBegin(GL_POLYGON);
glColor3f( 1.0, 0.0, 0.0 );
glVertex3f( 0.5, -0.5, -0.5 );
glVertex3f( 0.5, -0.5, 0.5 );
glVertex3f( -0.5, -0.5, 0.5 );
glVertex3f( -0.5, -0.5, -0.5 );
glEnd();
glEndList();
}
void setupGL() {
glClearColor(1, 1, 1, 0);
glEnable(GL_DEPTH_CLAMP);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glCullFace(GL_FRONT_AND_BACK);
}
int main(int, char const**)
{
sf::Window window(sf::VideoMode(1600, 1200), "OpenGL", sf::Style::Default, sf::ContextSettings(32));
window.setVerticalSyncEnabled(true);
//initWorld();
setupGL();
buildList();
while (running)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Process events
sf::Event event;
handleInput(window);
while (window.pollEvent(event))
{
// Close window: exit
if (event.type == sf::Event::Closed) {
running = false;
}
// Escape pressed: exit
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) {
running = false;
}
}
glCallList(cubelist);
// Update the window (c is a "Camera" object that just sets the perspective. I can provide code if necessary)
c.draw();
window.display();
}
return EXIT_SUCCESS;
}
EDIT: So changing the GL_POLYGONS statements to GL_QUADS seemed to fix the problem, but I'm still somewhat curious as to why.
Your first glBegin doesn't have a matching glEnd, this causes all the other glBegins to be ignored until the next glEnd. This means the front face leaked out to the back face.
That said immediate mode and the related displayList are deprecated, instead look into VBOs to store the vertex data.

How to find a point on the wall as a center point of a clock?

I create a cube as room and set camera inside it. I want to draw a clock on one of the walls. but when I draw a circle for showing clock, it doesn't work correctly. can anyone help me to draw a clock on the wall? here is my codes:
void room(){
if(flag){
glRotatef(rt,0.0f,1.0f,0.0f);
}
glEnable(GL_NORMALIZE);
glColor3f(1.0, 1.0 ,1.0); //roof
glNormal3f(0,-1,0);
glVertex3f( 3.0, 3.0,-3.0);
glVertex3f(-3.0, 3.0,-3.0);
glVertex3f(-3.0, 3.0, 3.0);
glVertex3f( 3.0, 3.0, 3.0);
glColor3f(1.0, 1.0 ,0.0); //floor
glNormal3f(0,1,0);
glVertex3f( 3.0,-3.0, 3.0);
glVertex3f(-3.0,-3.0, 3.0);
glVertex3f(-3.0,-3.0,-3.0);
glVertex3f( 3.0,-3.0,-3.0);
glColor3f(1.0, 0.0 ,0.0); //behind wall
glNormal3f(0,0,-1);
glVertex3f( 3.0, 3.0, 3.0);
glVertex3f(-3.0, 3.0, 3.0);
glVertex3f(-3.0,-3.0, 3.0);
glVertex3f( 3.0,-3.0, 3.0);
glColor3f( 0.0, 1.0,1.0); // front wall
glNormal3f(0,0,1);
glVertex3f( 3.0,-3.0,-3.0);
glVertex3f(-3.0,-3.0,-3.0);
glVertex3f(-3.0, 3.0,-3.0);
glVertex3f( 3.0, 3.0,-3.0);
glColor3f(0.0 ,0.0,1.0); //left wall
glNormal3f(1,0,0);
glVertex3f(-3.0, 3.0, 3.0);
glVertex3f(-3.0, 3.0,-3.0);
glVertex3f(-3.0,-3.0,-3.0);
glVertex3f(-3.0,-3.0, 3.0);
glColor3f( 0.2, 0.4, 0.0); // right wall
glNormal3f(-1,0,0);
glVertex3f( 3.0, 3.0,-3.0);
glVertex3f( 3.0, 3.0, 3.0);
glVertex3f( 3.0,-3.0, 3.0);
glVertex3f( 3.0,-3.0,-3.0);
}
void drawClock() {
char buff[100];
GLfloat x1=2.0;
GLfloat y1=2.0;
GLfloat z1=-3.0;
GLfloat radius = 1.0; // Radius
int angle;
glLoadIdentity();
//glClearColor(1.0, 1.0, 1.0, 1.0);
//glClear(GL_COLOR_BUFFER_BIT);
//glOrtho(0.0, 20.0, 0.0, 20.0, -10.0, 10.0);
// Draw circle
glPushMatrix();
glTranslatef(3.0,3.0,-3.0);
glBegin(GL_TRIANGLE_FAN);
glColor3f(0.5,1.0,0.0);
glVertex3f(x1, y1, z1);
for(angle=0; angle <= 360; angle +=1)
glVertex3f(x1 + cos(angle * PI/180.0f)* radius, y1 + sin(angle *PI/180.0f)* radius, z1);
glEnd();
glPopMatrix();
}
The center of the wall should be (0, 0, -3) not (2, 2, -3). Probably it's better to use however (0, 0, -2.9) so that the clock is slightly inside and not exactly on the wall.
Also I'd say that you need to add
glBegin(GL_QUADS);
at the start of room function and
glEnd();
at the end of it.
Also why are you calling glTranslatef before drawing the clock if it uses the same coordinate system as the walls?

OpenGL _ Front objects are covered with Back objects. so can't see it

The problem is, 'Objects on the table is covered with table board, so can't see it.'
( I using openGL 3.7 beta. Files that I installed is : http://ihoo1836.dothome.co.kr/opengl_vs2010+glutdlls37beta.zip )
All Codes are following.
#include<glut.h>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
float TableX = 5.0; //Table's X size
float TableY = 8.0; //Table's Y size
float TableHeight = 2.0;//Table's Height
int width=400, height=400; //Window Size
int ViewX = width/2; //for Change Viewpoint by Mouse position
int ViewY = height/2;
int ViewZ = 9;
GLUquadricObj* cyl;
void InitLight( ){
glEnable(GL_DEPTH_TEST); //for opaque
glEnable(GL_NORMALIZE); //normalize
glEnable(GL_SMOOTH); //for smooth color
glEnable(GL_LIGHTING); //light setting
glDepthMask(GL_TRUE);
GLfloat ambientLight[] = {0.3f, 0.3f, 0.3f, 1.0f};
GLfloat diffuseLight[] = {0.7f, 0.7f, 0.7f, 1.0f};
GLfloat specular[] = {1.0f, 1.0f, 1.0f, 1.0f};
GLfloat specref[] = {1.0f, 1.0f, 1.0f, 1.0f};
GLfloat position[]={400.0, 300.0, -700.0, 1.0};
glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
glLightfv(GL_LIGHT0, GL_SPECULAR, specular);
glLightfv(GL_LIGHT0, GL_POSITION, position);
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
glMateriali(GL_FRONT, GL_SHININESS, 128);
}
//Get Mouse Position to Change ViewPoint
void MyMouseMove(int button, int state, GLint X, GLint Y)
{
//Get Mouse Position X, Y
ViewX = X;
ViewY = Y;
glutPostRedisplay();
}
//Get Mouse Position to Change ViewPoint
void MyMotion(GLint X, GLint Y)
{
//Get Mouse Position X, Y
ViewX = X;
ViewY = Y;
glutPostRedisplay();
}
//Draw Table
void DrawTable(){
glPushMatrix();
glTranslatef(0.0,0.0,1.0);
glColor3f(0.5, 0.25, 0.0);
cyl = gluNewQuadric();
glRotatef(-90,1.0,0.0,0.0);
gluCylinder(cyl, 0.2, 0.2, TableHeight, 10, 20); //Leg of Table 1
glPushMatrix();
cyl = gluNewQuadric();
glTranslatef(TableX,0.0,0.0);
gluCylinder(cyl, 0.2, 0.2, TableHeight, 10, 20); //Leg of Table 2
glPushMatrix();
cyl = gluNewQuadric();
glTranslatef(0.0, TableY, 0.0);
gluCylinder(cyl, 0.2, 0.2, TableHeight, 10, 20); //Leg of Table 3
glPushMatrix();
cyl = gluNewQuadric();
glTranslatef(-TableX,0.0,0.0);
gluCylinder(cyl, 0.2, 0.2, TableHeight, 10, 20); //Leg of Table 4
glPushMatrix();
glTranslatef(TableX/2.0, -TableY/2, TableHeight);
glScalef(TableX+0.5, TableY+0.5, 0.5);
glutSolidCube(1); //Board of Table
glPopMatrix();
glPushMatrix(); //triangular1 (Beside of Net)
glTranslatef(0, -TableY/2, TableHeight);
glBegin(GL_TRIANGLES);
glVertex3f(TableY/16.0, 0, TableY/8.0);//1
glVertex3f(0, TableY/8.0, 0);
glVertex3f(0, -TableY/8.0, 0);
glVertex3f(TableY/16.0, 0, TableY/8.0);//2
glVertex3f(0, -TableY/8.0, 0);
glVertex3f(TableY/16.0, -TableY/8.0, 0);
glVertex3f(TableY/16.0, 0, TableY/8.0);//3
glVertex3f(TableY/16.0, -TableY/8.0, 0);
glVertex3f(TableY/16.0, TableY/8.0, 0);
glVertex3f(TableY/16.0, 0, TableY/8.0);//4
glVertex3f(TableY/16.0, TableY/8.0, 0);
glVertex3f(0, TableY/8.0, 0);
glEnd();
glPushMatrix(); //triangular2 (Beside of Net)
glTranslatef(TableX - TableY/8.0, 0 , 0);
glBegin(GL_TRIANGLES);
glColor3f(1.0, 0.0, 0.0);
glVertex3f(TableY/16.0, 0, TableY/8.0);//1
glColor3f(0.0, 1.0, 0.0);
glVertex3f(TableY/16.0, TableY/8.0, 0);
glColor3f(0.0, 0.0, 1.0);
glVertex3f(TableY/16.0, -TableY/8.0, 0);
glColor3f(1.0, 0.0, 0.0);
glVertex3f(TableY/16.0, 0, TableY/8.0);//2
glColor3f(0.0, 1.0, 0.0);
glVertex3f(TableY/16.0, -TableY/8.0, 0);
glColor3f(0.0, 0.0, 1.0);
glVertex3f(TableY/8.0, -TableY/8.0, 0);
glColor3f(1.0, 0.0, 0.0);
glVertex3f(TableY/16.0, 0, TableY/8.0);//3
glColor3f(0.0, 1.0, 0.0);
glVertex3f(TableY/8.0, -TableY/8.0, 0);
glColor3f(0.0, 0.0, 1.0);
glVertex3f(TableY/8.0, TableY/8.0, 0);
glColor3f(1.0, 0.0, 0.0);
glVertex3f(TableY/16.0, 0, TableY/8.0);//4
glColor3f(0.0, 1.0, 0.0);
glVertex3f(TableY/8.0, TableY/8.0, 0);
glColor3f(0.0, 0.0, 1.0);
glVertex3f(TableY/16.0, TableY/8.0, 0);
glEnd();
glPopMatrix();
glPushMatrix(); //Net
glBegin(GL_POLYGON);
glColor3f(1.0, 1.0, 1.0);
glVertex3f(TableY/16.0, 0.0, TableY/8.0);
glVertex3f((TableX - TableY/16.0), 0, TableY/8.0);
glVertex3f((TableX - TableY/16.0), 0, 0);
glVertex3f(TableY/16.0, 0.0, 0.0);
glEnd();
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPopMatrix();
}
//Display Callback Function
void MyDisplay( ){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity( );
gluPerspective(60.0, (GLfloat)width/height, 0.0, 10.0);
//Change Viewpoint by Mouse Position
gluLookAt((float)(ViewX - width/2)/width*20 + 2.5, (float)(height/2 - ViewY)/height*20 + 2.5, ViewZ, TableX/2, TableY/2, TableHeight, 0.0, 1.0, 0.0);
printf("eyex = %f , eyey = %f , eyez = %f \n",(float)(ViewX - width/2.0)/width*10, (float)(height/2 - ViewY)/height*10, (float)ViewZ);
DrawTable(); //Draw Table
glutSwapBuffers(); //for 'Double Buffering'
}
//for Reshape Window
void MyReshape (int w, int h){
width = w;
height = h;
printf("width = %d, height = %d \n", width, height);
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity( );
glOrtho (-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
}
//Main Function
int main(int argc, char** argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
glutInitWindowSize(width, height);
glutInitWindowPosition(200, 200);
glutCreateWindow("OpenGL Sample Drawing");
glClearColor(0.4, 0.4, 0.4, 1.0);
InitLight(); //set Light Setting
glutDisplayFunc(MyDisplay);
glutMouseFunc(MyMouseMove); //get Mouse Position, to Change Viewpoint
glutMotionFunc(MyMotion); //get Mouse Position, to Change Viewpoint
glutReshapeFunc(MyReshape);
glutMainLoop( );
}
The third argument to gluPerspective() should be non-zero, positive, and less than the forth argument:
#include <GL/glut.h>
#include <stdio.h>
float TableX = 5.0; //Table's X size
float TableY = 8.0; //Table's Y size
float TableHeight = 2.0;//Table's Height
int ViewX = 400/2; //for Change Viewpoint by Mouse position
int ViewY = 400/2;
int ViewZ = 9;
GLUquadricObj* cyl;
void InitLight( ){
glEnable(GL_DEPTH_TEST); //for opaque
glEnable(GL_NORMALIZE); //normalize
glEnable(GL_SMOOTH); //for smooth color
glEnable(GL_LIGHTING); //light setting
glDepthMask(GL_TRUE);
GLfloat ambientLight[] = {0.3f, 0.3f, 0.3f, 1.0f};
GLfloat diffuseLight[] = {0.7f, 0.7f, 0.7f, 1.0f};
GLfloat specular[] = {1.0f, 1.0f, 1.0f, 1.0f};
GLfloat specref[] = {1.0f, 1.0f, 1.0f, 1.0f};
GLfloat position[]={400.0, 300.0, -700.0, 1.0};
glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
glLightfv(GL_LIGHT0, GL_SPECULAR, specular);
glLightfv(GL_LIGHT0, GL_POSITION, position);
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
glMateriali(GL_FRONT, GL_SHININESS, 128);
}
//Get Mouse Position to Change ViewPoint
void MyMouseMove(int button, int state, GLint X, GLint Y)
{
//Get Mouse Position X, Y
ViewX = X;
ViewY = Y;
glutPostRedisplay();
}
//Get Mouse Position to Change ViewPoint
void MyMotion(GLint X, GLint Y)
{
//Get Mouse Position X, Y
ViewX = X;
ViewY = Y;
glutPostRedisplay();
}
//Draw Table
void DrawTable(){
glPushMatrix();
glTranslatef(0.0,0.0,1.0);
glColor3f(0.5, 0.25, 0.0);
cyl = gluNewQuadric();
glRotatef(-90,1.0,0.0,0.0);
gluCylinder(cyl, 0.2, 0.2, TableHeight, 10, 20); //Leg of Table 1
glPushMatrix();
cyl = gluNewQuadric();
glTranslatef(TableX,0.0,0.0);
gluCylinder(cyl, 0.2, 0.2, TableHeight, 10, 20); //Leg of Table 2
glPushMatrix();
cyl = gluNewQuadric();
glTranslatef(0.0, TableY, 0.0);
gluCylinder(cyl, 0.2, 0.2, TableHeight, 10, 20); //Leg of Table 3
glPushMatrix();
cyl = gluNewQuadric();
glTranslatef(-TableX,0.0,0.0);
gluCylinder(cyl, 0.2, 0.2, TableHeight, 10, 20); //Leg of Table 4
glPushMatrix();
glTranslatef(TableX/2.0, -TableY/2, TableHeight);
glScalef(TableX+0.5, TableY+0.5, 0.5);
glutSolidCube(1); //Board of Table
glPopMatrix();
glPushMatrix(); //triangular1 (Beside of Net)
glTranslatef(0, -TableY/2, TableHeight);
glBegin(GL_TRIANGLES);
glVertex3f(TableY/16.0, 0, TableY/8.0);//1
glVertex3f(0, TableY/8.0, 0);
glVertex3f(0, -TableY/8.0, 0);
glVertex3f(TableY/16.0, 0, TableY/8.0);//2
glVertex3f(0, -TableY/8.0, 0);
glVertex3f(TableY/16.0, -TableY/8.0, 0);
glVertex3f(TableY/16.0, 0, TableY/8.0);//3
glVertex3f(TableY/16.0, -TableY/8.0, 0);
glVertex3f(TableY/16.0, TableY/8.0, 0);
glVertex3f(TableY/16.0, 0, TableY/8.0);//4
glVertex3f(TableY/16.0, TableY/8.0, 0);
glVertex3f(0, TableY/8.0, 0);
glEnd();
glPushMatrix(); //triangular2 (Beside of Net)
glTranslatef(TableX - TableY/8.0, 0 , 0);
glBegin(GL_TRIANGLES);
glColor3f(1.0, 0.0, 0.0);
glVertex3f(TableY/16.0, 0, TableY/8.0);//1
glColor3f(0.0, 1.0, 0.0);
glVertex3f(TableY/16.0, TableY/8.0, 0);
glColor3f(0.0, 0.0, 1.0);
glVertex3f(TableY/16.0, -TableY/8.0, 0);
glColor3f(1.0, 0.0, 0.0);
glVertex3f(TableY/16.0, 0, TableY/8.0);//2
glColor3f(0.0, 1.0, 0.0);
glVertex3f(TableY/16.0, -TableY/8.0, 0);
glColor3f(0.0, 0.0, 1.0);
glVertex3f(TableY/8.0, -TableY/8.0, 0);
glColor3f(1.0, 0.0, 0.0);
glVertex3f(TableY/16.0, 0, TableY/8.0);//3
glColor3f(0.0, 1.0, 0.0);
glVertex3f(TableY/8.0, -TableY/8.0, 0);
glColor3f(0.0, 0.0, 1.0);
glVertex3f(TableY/8.0, TableY/8.0, 0);
glColor3f(1.0, 0.0, 0.0);
glVertex3f(TableY/16.0, 0, TableY/8.0);//4
glColor3f(0.0, 1.0, 0.0);
glVertex3f(TableY/8.0, TableY/8.0, 0);
glColor3f(0.0, 0.0, 1.0);
glVertex3f(TableY/16.0, TableY/8.0, 0);
glEnd();
glPopMatrix();
glPushMatrix(); //Net
glBegin(GL_POLYGON);
glColor3f(1.0, 1.0, 1.0);
glVertex3f(TableY/16.0, 0.0, TableY/8.0);
glVertex3f((TableX - TableY/16.0), 0, TableY/8.0);
glVertex3f((TableX - TableY/16.0), 0, 0);
glVertex3f(TableY/16.0, 0.0, 0.0);
glEnd();
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPopMatrix();
}
//Display Callback Function
void MyDisplay( ){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode (GL_PROJECTION);
glLoadIdentity( );
double width = glutGet( GLUT_WINDOW_WIDTH );
double height = glutGet( GLUT_WINDOW_HEIGHT );
gluPerspective(60.0, (GLfloat)width/height, 0.01, 100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity( );
//Change Viewpoint by Mouse Position
gluLookAt((float)(ViewX - width/2)/width*20 + 2.5, (float)(height/2 - ViewY)/height*20 + 2.5, ViewZ, TableX/2, TableY/2, TableHeight, 0.0, 1.0, 0.0);
printf("eyex = %f , eyey = %f , eyez = %f \n",(float)(ViewX - width/2.0)/width*10, (float)(height/2 - ViewY)/height*10, (float)ViewZ);
DrawTable(); //Draw Table
glutSwapBuffers(); //for 'Double Buffering'
}
//Main Function
int main(int argc, char** argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
glutInitWindowSize(400, 400);
glutInitWindowPosition(200, 200);
glutCreateWindow("OpenGL Sample Drawing");
glClearColor(0.4, 0.4, 0.4, 1.0);
InitLight(); //set Light Setting
glEnable( GL_DEPTH_TEST );
glutDisplayFunc(MyDisplay);
glutMouseFunc(MyMouseMove); //get Mouse Position, to Change Viewpoint
glutMotionFunc(MyMotion); //get Mouse Position, to Change Viewpoint
glutMainLoop( );
}

C++ OpenGL lighting only lights certain walls

I am lighting my scene in opengl and there are 4 walls, only 2 of them are being lit.
I think it is something wrong with the normals but I am not sure.
This is the lighting code:
glShadeModel(GL_SMOOTH);
//glEnable(GL_CULL_FACE);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
GLfloat lightpos0[] = {-5, 1, 0, 0.};
GLfloat AmbientLight0[] = {0.2, 0.2, 0.2,1.0};
GLfloat DiffuseLight0[] = {0.8, 0.8, 0.8,1.0};
GLfloat SpecularLight0[] = {1.0, 1.0, 1.0,1.0};
glLightfv(GL_LIGHT0, GL_POSITION, lightpos0);
glLightfv(GL_LIGHT0, GL_AMBIENT, AmbientLight0);
glLightfv(GL_LIGHT0, GL_DIFFUSE, DiffuseLight0);
glLightfv(GL_LIGHT0, GL_SPECULAR, SpecularLight0);
GLfloat lightpos1[] = {5, 1, 0, 0};
GLfloat AmbientLight1[] = {0.2, 0.2, 0.2,1.0};
GLfloat DiffuseLight1[] = {0.8, 0.8, 0.8,1.0};
GLfloat SpecularLight1[] = {1.0, 1.0, 1.0,1.0};
glLightfv(GL_LIGHT1, GL_POSITION, lightpos1);
glLightfv(GL_LIGHT1, GL_AMBIENT, AmbientLight1);
glLightfv(GL_LIGHT1, GL_DIFFUSE, DiffuseLight1);
glLightfv(GL_LIGHT1, GL_SPECULAR, SpecularLight1);
This is the code for drawing the 4 walls.
//north
glBegin(GL_QUADS);
glNormal3f(1.0,0,0);
glVertex3f(-10,0,-10);
glVertex3f( 10,0,-10);
glVertex3f( 10,5,-10);
glVertex3f(-10,5,-10);
glEnd();
//south
glBegin(GL_QUADS);
glNormal3f(-1.0, 0, 0);
glVertex3f(-10,0, 10);
glVertex3f( 10,0, 10);
glVertex3f( 10,5, 10);
glVertex3f(-10,5, 10);
glEnd();
//east
glBegin(GL_QUADS);
glNormal3f(0,0, -1.0);
glVertex3f( 10,0,-10);
glVertex3f( 10,0,10);
glVertex3f( 10,5,10);
glVertex3f( 10,5,-10);
glEnd();
//west
glBegin(GL_QUADS);
glNormal3f(0,0,1.0);
glVertex3f( -10,0,-10);
glVertex3f( -10,0,10);
glVertex3f( -10,5,10);
glVertex3f( -10,5,-10);
glEnd();
If it helps, here's and image of whats happening: http://i.stack.imgur.com/xRgVL.png
As pointed out by Vladislav Khorev, the normals must be directed out of the coordinate that is common to all points (given this special orthogonal arrangement).
But also one should consider the winding of the polygons:
// Polygon A -- north Polygon B -- south
glVertex3f(-10,0,-10); glVertex3f(-10,0, 10);
glVertex3f( 10,0,-10); glVertex3f( 10,0, 10);
glVertex3f( 10,5,-10); glVertex3f( 10,5, 10);
glVertex3f(-10,5,-10); glVertex3f(-10,5, 10);
Normal(0,0,1), Normal(0,0,-1);
The two polygons (north and south), are of different winding. The first is ClockWise observed from point 0,0,0 and the other of CCW. One should be consistent with these.
It seems that you pass wrong normal vector to walls.
If your wall got Z = -10 for all points (wall is parallel to X), then it must have normal vector directed in positive direction of Z: (0,0,1).
Same is true for all directions.
Try this:
glBegin(GL_QUADS);
glNormal3f(0,0,1);
glVertex3f(-10,0,-10);
glVertex3f( 10,0,-10);
glVertex3f( 10,5,-10);
glVertex3f(-10,5,-10);
glEnd();
//south
glBegin(GL_QUADS);
glNormal3f(0, 0, -1);
glVertex3f(-10,0, 10);
glVertex3f( 10,0, 10);
glVertex3f( 10,5, 10);
glVertex3f(-10,5, 10);
glEnd();
//east
glBegin(GL_QUADS);
glNormal3f(-1,0, -0);
glVertex3f( 10,0,-10);
glVertex3f( 10,0,10);
glVertex3f( 10,5,10);
glVertex3f( 10,5,-10);
glEnd();
//west
glBegin(GL_QUADS);
glNormal3f(1, 0, 0);
glVertex3f( -10,0,-10);
glVertex3f( -10,0,10);
glVertex3f( -10,5,10);
glVertex3f( -10,5,-10);
glEnd();