Texture mapping in Doc- View architecture

Hello,
I am using MFC for my openGL development.
The problem i am facing now is with Texture mapping.On executing the program, initally the sphere is texture mapped and lighted correctly. but on repainting or resizing i am loosing all effects.
I am initalizing lighting and texture mapping parameters in View Initialization.
all parameters are part of Document class.

can some one explain me , what am I doing wrong.
regards

It is very posible that lighting and texture are not called by redraw routines.

Try:
display()
{
//draw everything you need
draw_texture_and_lighting();
}

//calling by
{
glutInitDisplayMode(…);

glutDisplayFinc(display);

}
All the action call by display, will be drawn in cas of a resize.

If somebody else has an other idea…

Pip, he was asking about MFC, not glut.

As to the question at hand, put a breakpoint at the step where you bind the texture (I’m assuming you’re working with texture objects and not just a single glTexture2D). If it is only being called once, you need to make sure you call it for every call of OnDraw (probably in your redrawing code).

You should also check for errors through glError.

What do you mean exactly by “losing all your effects?” Does the whole scene disappear? If that’s the case, it’s very likely that you are multiplying your new frustum/ortho projection to your current one rather than replacing it. For example if you had this in your resize

glMatrixMode(GL_PROJECTION);
gluPerspective(60, width/height, 1.0 , 20.0);
glMatrixMode(GL_MODELVIEW);
gluLookAt(0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

Then initially your perspective and “camera” would be what you wanted. On a resize, though, you would end up moving the “camera” back ANOTHER 10 units, and changing your projection matrix drastically. Instead you would do this.

glMatrixMode(GL_PROJECTION);
glLoadIdentity(); // reset the projection matrix first
gluPerspective(60, width/height, 1.0 , 20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); // reset the model-view matrix first
gluLookAt(0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

Pip,
I should also mention something else…

display()
{
//draw everything you need
draw_texture_and_lighting();
}

is not correct if you mean that the
// draw everything you need
to be the actual drawing stuff and
draw_texture_and_lighting();
to be the texture/lighting setup. They should be the other way around. OpenGL is a state machine. When you draw something it will use the current state. So if you set the texture and lighting AFTER drawing your object, you won’t have any affect. However, it WILL affect the next object you draw.