PDA

View Full Version : texture mapping, loading up an image, DevIL



annette
02-02-2012, 08:52 AM
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
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(Angle, 0.0, 0.0, 0.0);

glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);

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


// Draw our texture
glEnable(GL_TEXTURE_2D);


//Nose
drawTriangle();

//Face
circle (250, 250, 400);


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

//Eye lids
glLoadIdentity();
glScalef(0.6,0.2,0);
circle(530, 2400, 60);
circle(-150, 2150, 60);

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

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

glDisable(GL_TEXTURE_2D);

// ----- 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);
glBegin(GL_LINE_LOOP);
for (int i = 0; i < 100; i++)
{
angle = i*2*PI/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));
}
glEnd();

}


And my main function looks like this:


int main (int argc, char** argv)
{
glutInit (&amp;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?

Captain Code
02-02-2012, 09:21 AM
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.

e.g.

setup camera

.... draw face routine
pushMatrix(GL_MODELVIEW)
specify translate commands as necessary
specify rotate commands as necessary
popMatrix()

... draw Eyes
pushMatrix(GL_MODELVIEW)
specify translate commands as necessary
specify rotate commands as necessary
popMatrix()

etc....

Alfonse Reinheart
02-02-2012, 09:24 AM
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.

carsten neumann
02-02-2012, 09:56 AM
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.

annette
02-02-2012, 10:29 AM
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.

annette
03-03-2012, 03:12 PM
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.