texture mapping, loading up an image, DevIL

I keep getting a black, blue or white screen depending on the alterations I make to my code but the image does not upload. I think the problem is with the display function. I have functions in the display function but I don’t think that should matter. My display function looks something like this:

void display(void)

//clear the screen


 glRotatef(Angle, 0.0, 0.0, 0.0);

  // Select the texture to use
glBindTexture(GL_TEXTURE_2D, texture[0]);

// Draw our texture



circle (250, 250, 400);

//Inner Eyes
circle(200, 280, 10);
drawCircle1(-30, 280, 10);

//Eye lids
circle(530, 2400, 60);
circle(-150, 2150, 60);

//Arc for eyebrows
drawArc(500, 500, -70, -140, 100);
drawArc(270, 500, -70, -140, 100);

drawArc(380, 250, 110, -180, 180);
// drawArc(380, 100, -100, -180, 180);


// ----- Stop Drawing Stuff! ------

glfwSwapBuffers(); // Swap the buffers to display the scene (so we don’t have to watch it being drawn!)


An example of the circle function is:

void circle(GLint x, GLint y, GLint radius)
float angle;

glTranslatef(300, 100, 0.0);

glTranslatef(0.0,150.0, 1.0);

glColor3f(0.0f, 1.0f, 0.0f);
for (int i = 0; i < 100; i++)
angle = i2PI/100;
float X = x + (cos(angle) * radius);
float Y = y + (sin(angle) * radius);
glVertex2f(X, Y);
//glVertex2f(x + (cos(angle) * radius), y + (sin(angle) * radius));


And my main function looks like this:

int main (int argc, char** argv)
glutInit (&argc, argv);
// Initialize GLUT
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition (100, 100);
glutInitWindowSize (winWidth, winHeight); // Set the initial Window’s width and height
glutCreateWindow (“Facial Expression Recognition Project”);// Create window with the given title

glutDisplayFunc (display); // Register callback handler for window re-paint event
glutMainLoop ( ); // Enter infinitely event-processing loop


Could it be the display function or it is something else?

OpenGL does not have the concept of a separate Model and View Matrix. Instead it has one combined matrix the MODEL_VIEW.

This means you need to ensure when you draw your model that you preserve the VIEW portion of the Model-view-matrix. You can do this by using the pushMatrix() and PopMatrix commands to encapsulate each part of your model drawing routines.

This may be your issue.


setup camera

… draw face routine
specify translate commands as necessary
specify rotate commands as necessary

… draw Eyes
specify translate commands as necessary
specify rotate commands as necessary


It could be anything. That’s why it’s a good idea to change only one thing at a time.

If you want to test your texture upload code, write a simple application that draws a single quad to the screen that has a texture mapped to it. That texture should come from memory (ie: create an array of some data, perhaps the same value for each texel, whatever, and upload it with glTexImage2D). Once you have that working, then you know that your display code works. Then you change where your texture comes from: load it with DevIL and upload what it gives you.

If it continues to work, then you know your loading code is fairly solid. If it stops working, then you know you did something wrong in your loading code.

Don’t try to change too much all at once.

Also, do you intend to draw lines that use the texture? If not, then you should unbind and disable the texture unit, and then use glTexEnv to just take the per-vertex color.

You are not specifying texture coordinates in your circle drawing function, so all vertices will have the same texture coordinates (whatever they were last set to) and a single pixel of your texture gets mapped to the whole primitive.

Wow. Thanks everyone for your prompt response. I’ve taken note of all your comments and suggestions. I’ll work on it right away and let you know if it works. Thanks so much again.

carsten neumann was right. The problem was with my texture coordinates. Once I took care of that, I was able to upload my image. Sorry it took a while for me to respond. Thanks.