0
\$\begingroup\$

I'm having an issue getting OpenGL ES 1.1 to draw anything. All I get is a black screen every time.

I have the following working OpenGL 2.1 code, which I'm trying to change over:

glClearColor(0.0, 0.0, 0.0, 0.0);
glViewport(0, 0, width, height);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

glOrtho(0.0f, width, height, 0.0f, -1.0f, 1.0f);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glEnable(GL_POINT_SMOOTH);

glBegin(GL_LINES);
glColor4ub(r, g, b, a);
glVertex2i(40, 40);
glVertex2i(60, 60);
glEnd();

I have converted it as follows:

glClearColor(0.0, 0.0, 0.0, 0.0);
glViewport(0, 0, width, height);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

glOrthof(0.0f, width, height, 0.0f, -1.0f, 1.0f);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glEnable(GL_POINT_SMOOTH);

glEnableClientState(GL_VERTEX_ARRAY);
glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

GLshort vertexData[] = {
    static_cast<GLshort>(x1), static_cast<GLshort>(y1), 0,
    static_cast<GLshort>(x2), static_cast<GLshort>(y2), 0
};

glColor4ub(r, g, b, a);
glVertexPointer(3, GL_SHORT, 0, &vertexData);
glDrawArrays(GL_LINES, 0, 2);

Where am I going wrong? I have also tried drawing all kinds of other shapes, including triangles, and end up with the same problem.

I just get a black screen every single time and I have no indication of what's going on.

\$\endgroup\$
  • \$\begingroup\$ On further investigation, it turns out that the same code runs properly under OpenGL 2.1, with the exception of the glOrthof function, which isn't available, only glOrtho. So, that begs the question - what is the difference between these two functions? \$\endgroup\$ – user10504 Jan 29 '19 at 8:44

Your Answer

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

Browse other questions tagged or ask your own question.