What am I missing here? All I’m attempting to do at this point is create a blank floor, but all I’m getting is a black screen. I’ll admit that despite reading tutorial after tutorial OpenGL still confuses me senseless but… I’ve matched a lot of this up against what I’ve seen elsewhere… What am I doing wrong here?
#include <iostream>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
using namespace std;
void init(void){
glEnable(GL_DEPTH_TEST);
}
void resize(int w, int h){
// prevent divide by zero
if(h == 0) { h = 1; }
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0,0,w,h);
gluPerspective(45, 1, 0, 1000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0, 3, 5, 0, 0, 0, 0.0f, 1.0f, 0.0f);
}
void renderScene(void){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// draw ground
glColor3f(1, 0, .5);
glBegin(GL_QUADS);
glVertex3f(200, 0, 200);
glVertex3f(-200, 0, 200);
glVertex3f(-200, 0, -200);
glVertex3f(200, 0, -200);
glEnd();
glutSwapBuffers();
}
int main(int argc, char **argv)
{
// initialize glut
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100,00);
glutInitWindowSize(800,800);
init();
glutDisplayFunc(renderScene);
glutIdleFunc(renderScene);
glutReshapeFunc(resize);
glutCreateWindow("3d test");
glutMainLoop();
return 0;
}
Any advice here would be great… I’m evidently a horrible graphics programmer because I can’t understand this stuff for the life of me and they’ve literally just thrown me head first into it at work. Wonderful, right?