Skip to main content
gamedev.net
🔒 Locked

Weird rendering problem

Started by uzipaz Sep 9, 2011 at 11:14 AM 2 replies 1.4k views
Original Post
uzipaz
uzipaz
I am have been using GLUT 3.7.6 for quite a while now... I have done some practice programs that render simple polygons and animate them.

Now... few days ago... I compiled a program that just rendered a triangle(no animations)... when I executed the program, the triangle appeared with desired results... now I change my window(Select internet explorer or any other application).... then click back to the opengl... the triangle became smaller... then I repeated the same thing.... the triangle became much smaller until it disappeared...

So, I set a callback to IdleFunc with Rendering function.... Now, when I execute the program, the triangle that is rendered becomes smaller very fast and disappears...

Thats the best explanation of the problem I can give right now....

I have the code of the program... I have done rendering and animation of simple polygons... it worked perfectly.... but I don't have a clue about what is going right now....



#include <GL\glut.h>

void changeSize(int w, int h) {

// Prevent a divide by zero, when window is too short
// (you cant make a window of zero width).
if (h == 0)
h = 1;

float ratio = w * 1.0 / h;

// Use the Projection Matrix
glMatrixMode(GL_PROJECTION);

// Reset Matrix
glLoadIdentity();

// Set the viewport to be the entire window
glViewport(0, 0, w, h);

// Set the correct perspective.
gluPerspective(45.0f, ratio, 0.1f, 100.0f);

// Get Back to the Modelview
glMatrixMode(GL_MODELVIEW);
}

void RenderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

gluLookAt(0, 0, 5,
0, 0, 0,
0, 1, 0);

glBegin(GL_TRIANGLES);
glVertex2f(2, 3);
glVertex2f(-3, 3);
glVertex2f(-3, -3);
glEnd();

glutSwapBuffers();
}

int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
// glutInitWindowSize(640, 480);
glutCreateWindow("Practice 3");

glutDisplayFunc(RenderScene);
glutReshapeFunc(changeSize);
// glutIdleFunc(RenderScene);

glutMainLoop();

return 0;
}



If I don't use the 'changeSize' function, I does'nt render anything.......

Any ideas?
Brother Bob
Brother Bob
You have to reset the modelview matrix every time you redraw your scene, or the matrix generated by gluLookAt will accumulate every time the sceren is drawn.
uzipaz
uzipaz

You have to reset the modelview matrix every time you redraw your scene, or the matrix generated by gluLookAt will accumulate every time the sceren is drawn.


How will I do that?
Sorry, I dont have in depth knowledge of computer graphics...
Brother Bob
Brother Bob
You use glLoadIdentity. Your code even has a comment helping you:
[source]
// Reset Matrix
glLoadIdentity();
[/source]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.