# OpenGL 2D Origin in Upper Left Corner

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);
glOrtho(0, MonitorWidth, MonitorHeight, 0, -1, 1);
glMatrixMode(GL_MODELVIEW);

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

glColor3f(1, 1, 1);

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?

• You should avoid using deprecated opengl feqtures – Bálint Mar 28 '17 at 8:53
• @Bálint - that seems neither relevant nor helpful - depending on the source of the problem, it may well occur with modern GL features too. – Maximus Minimus Mar 28 '17 at 11:18
• @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. – Bálint Mar 28 '17 at 17:33

Aright I fixed it:

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

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

glColor3f(1, 1, 1);