Simply put the gluPerspective call creates a black screen. If I comment out gluPerspective, the white triangle persists as predicted.
I’ve researched this problem, however it seems when people have solved it they don’t stick around and document the answer. I’ve checked it against github however I am not using visual studio ide.
#define GLUT_DISABLE_ATEXIT_HACK
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
void changeSize(int w, int h)
{
if(h == 0)
h = 1;
float ratio = 1.0* w / h;
//use projection mode
glMatrixMode(GL_PROJECTION);
// reset matrix
glLoadIdentity();
// Set the viewport to be the entire window
glViewport(0,0,w,h);
// Set the correct perspective.
//gluPerspective(45,ratio,1,100);
gluPerspective(45.0f,ratio,0.1f,100.0f);
//glOrtho(-40/3.0f,40/3.0f,-10,10,-10,10);
// Get Back to the Modelview
glMatrixMode(GL_MODELVIEW);
}
void renderScene(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glVertex3f(-0.5,-0.5,0.0);
glVertex3f(0.5,0.0,0.0);
glVertex3f(0.0,0.5,0.0);
glEnd();
glutSwapBuffers();
}
int main(int argc, char **argv) {
// init GLUT and create Window
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(320,320);
glutCreateWindow("Lighthouse3D - GLUT Tutorial - reshape");
// register callbacks
glutDisplayFunc(renderScene);
glutReshapeFunc(changeSize);
// enter GLUT event processing cycle
glutMainLoop();
return 1;
}