PDA

View Full Version : Drawing a door for a (very simple) house



agentkirb
07-10-2010, 03:49 PM
I'm an ultra-begginner when it comes to programming in OpenGL. I'm taking a summer Graphics class and so far we've learned how to make a cube 1 unit long centered at 0,0,0 and mess with the camera angles and all that. The first major project is to do the front part of a house (a door and a window.. no roof yet). I've obviously gotten it to run with just the "cube" house, but when I try to put the door on there it doesn't work. Havn't even tried a window yet.

I'll try looking for example model house files to compare with, but if anyone can figure out what I'm doing wrong any help would be appreciated.




#include <stdlib.h>

#ifdef __APPLE_
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif

typedef float vertex[3];

vertex vertices[]={
{-0.5, -0.5, 0.5},//0 (first 8 verticies for cube)
{-0.5, 0.5, 0.5},//1
{0.5, 0.5, 0.5},//2
{0.5, -0.5, 0.5},//3
{-0.5, -0.5, -0.5},//4
{-0.5, 0.5, -0.5},//5
{0.5, 0.5, -0.5},//6
{0.5, -0.5, -0.5},//7
{-3/28, -13/28, 0.5},//8 (start door) bottom left
{3/28, -13/28, 0.5},//9 bottom right
{3/28, 0, 0.5},//10 top right
{-3/28,0, 0.5}}//11 top left
;


static GLfloat theta[] = {0.0,0.0,0.0};


void face( int a, int b, int c, int d)
{
glBegin(GL_POLYGON);
glNormal3fv(vertices[a]);
glVertex3fv(vertices[a]);
glVertex3fv(vertices[B]);
glVertex3fv(vertices[c]);
glVertex3fv(vertices[d]);
glEnd();
}

void MYcube()
{
glColor3f(1.0,0.0,0.0); //red),
face(0,3,2,1);
glColor3f(0.0,1.0,0.0); //green),
face(4,5,6,7);
glColor3f(0.0,0.75388,1.0); //blue),
face(5,1,2,6);
glColor3f(1.0,0.2,0.7); //deep pink),
face(4,7,3,0);
glColor3f(1.0,1.0,0.0); // yellow),
face(2,3,7,6);
glColor3f(1.0,0.75,0.0); // orange).
face(5,4,0,1);
glColor3f(0.0,0.0,0.0); //red),
face(8,9,10,11);
}





void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glLoadIdentity();
gluLookAt(0.0 ,0.0 ,1.0,
0.0 ,0.0 ,0.0,
0.0 ,1.0 ,0.0);
MYcube();

glFlush();


}


void myReshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w <= h)
glOrtho(-1.0, 1.0, -1.0 * (GLfloat) h / (GLfloat) w,
1.0 * (GLfloat) h / (GLfloat) w, -5.0, 5.0);
else
glOrtho(-2.0 * (GLfloat) w / (GLfloat) h,
2.0 * (GLfloat) w / (GLfloat) h, -2.0, 2.0, -10.0, 10.0);
glMatrixMode(GL_MODELVIEW);

glutPostRedisplay();
}

void main(int argc, char **argv)
{

glutInit(&amp;argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(500, 500);
glutCreateWindow("Chambers House");
glutReshapeFunc(myReshape);
glutDisplayFunc(display);
glEnable(GL_DEPTH_TEST);
glClearColor (1.0, 1.0, 1.0, 1.0);
glutMainLoop();
}


When I build this I just see the red face of the front, even though I added 4 more vertices and made a face with a different color than the front. I'm sure it's some beginner's mistake I'm making.