PDA

View Full Version : Strange output



Deon588
02-09-2015, 06:08 AM
Hi all I am currently busy with a computer graphics course and completely new to opengl... I have to create a room where 2 walls are visible and add several items to the room afterwards... Right now i'm just trying to display the floor and walls but keep getting a blank white window as output. Any idea what i'm doing wrong?
My code:
#include <gl/glut.h>

/*defining colors used in the room*/
GLfloat black[] = {0.0, 0.0, 0.0, 1.0};
GLfloat white[] = {1.0, 1.0, 1.0, 1.0};
GLfloat brown = {165.0/255.0, 42.0/255.0, 42.0/255.0, 1.0};

void myInit()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, 500, 500);
gluPerspective(60, 1, 1, 500);
glMatrixMode(GL_MODELVIEW);
}

void drawFloor()
{
glBegin(GL_POLYGON);
glColor4fv(black);
glVertex3f(0.0, 0.0, -3.0);
glVertex3f(1.0, 0.0, -3.0);
glVertex3f(2.0, 0.0, -3.0);
glEnd();
}

void drawWalls()
{
glBegin(GL_QUAD_STRIP);
glColor4fv(white);
//draw left wall
glVertex3f(0.0, 0.0, -3.0);
glVertex3f(0.0, 1.0, -3.0);
glVertex3f(0.0, 0.0, -2.0);
glVertex3f(0.0, 1.0, -2.0);
glVertex3f(0.0, 0.0, -1.0);
glVertex3f(0.0, 1.0, -1.0);

//draw front wall
glVertex3f(1.0, 0.0, -3.0);
glVertex3f(1.0, 1.0, -3.0);
glVertex3f(2.0, 0.0, -3.0);
glVertex3f(2.0, 1.0, -3.0);
glVertex3f(3.0, 0.0, -3.0);
glVertex3f(3.0, 1.0, -3.0);
glEnd();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
drawFloor();
drawWalls();
glFlush();

}

void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, (GLfloat) w / (GLfloat) h, 1, 500);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(500, 500);
glutInitWindowPosition(0, 0);
glutCreateWindow("My room");
glEnable(GL_DEPTH_TEST);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
myInit();
glutMainLoop();
}


Thanks