0
\$\begingroup\$

I got an OpenGL Context Working in SDL, and I'm trying to set it up so I can render with pixel coordinates of the screen. I got this trying to fill the entire screen with a white rectangle:

glViewport(0, 0, MonitorWidth, MonitorHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, MonitorWidth, MonitorHeight, 0, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glColor3f(1, 1, 1);

glBegin(GL_QUADS);

glVertex2f(0, 0);
glVertex2f(MonitorWidth, 0);
glVertex2f(MonitorWidth, MonitorHeight);
glVertex2f(0, MonitorHeight);

glEnd();

It doesn't work, and the entire screen appears black. What's wrong with this?

\$\endgroup\$
  • \$\begingroup\$ You should avoid using deprecated opengl feqtures \$\endgroup\$ – Bálint Mar 28 '17 at 8:53
  • \$\begingroup\$ @Bálint - that seems neither relevant nor helpful - depending on the source of the problem, it may well occur with modern GL features too. \$\endgroup\$ – Maximus Minimus Mar 28 '17 at 11:18
  • \$\begingroup\$ @LeComte That's why I didn't post it as an answer. I try to steer people towards better solutions. OpenGL 1.0 is deprecated since ages and GPUs started to drop support for it. \$\endgroup\$ – Bálint Mar 28 '17 at 17:33
-1
\$\begingroup\$

Aright I fixed it:

glViewport(0, 0, MonitorWidth, MonitorHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, MonitorWidth, MonitorHeight, 0, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glClearColor(1, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glColor3f(1, 1, 1);

glBegin(GL_QUADS);

glVertex2i(0, 0);
glVertex2i(MonitorWidth, 0);
glVertex2i(MonitorWidth, MonitorHeight);
glVertex2i(0, MonitorHeight);

glEnd();
\$\endgroup\$
  • 2
    \$\begingroup\$ ...the only difference I can see in the code presented is that you changed your clear color from black to red. \$\endgroup\$ – Trevor Powell Mar 28 '17 at 4:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.