Archived

This topic is now archived and is closed to further replies.

Jacob84

Disgusting mistakes...

Recommended Posts

Hi everybody (First post over the OGL forum ) : Maybe this question is almost stupid, i don''t know, it''s probably a problem of concepts ''bout 3D, but at the moment I can''t find the answer. The problem appears when using space 3D management functions, like glTranslatef , for example, but after testing some things i don''t know if the problem is over the coordinates system (Is this possible???). The most disgusting aspect, is to me , that the problem appears even if I use examples , that you can find over webs (NeHe) or books (Programming over OpenGL). for example (Very simple) -> void Render(void){ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glTranslatef(-1.5f,0.0f,-6.0f); glBegin(GL_TRIANGLES); // Code of triangle here glEnd(); } Here glTranslatef moves the scene 1.5 units left, and 6 into the screen. Well, if I use this, the window appears black. But, if I use glTranslatef(0.0f,0.0f,0.0f) appears correctly. If I try to translate the scene 1 unit into the window appears ok, but if I try -1.1f appears black. It seems like the coordinates used in the NeHe example doesn''t work in my system!!! Thanks for reading, Jacob.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
if not stated otherwise glTranslatef(x,y,z); affects the current modelview matrix as in rewrites elements 12,13,14 with those supplied by you.The problem is that the projection plane is set "in front" of your triangle , try glTranslate-ing after drawing the triangle.

Share this post


Link to post
Share on other sites
"If I try to translate the scene 1 unit into the window appears ok, but if I try -1.1f appears black."

then i would first check the near and far planes you set.

Share this post


Link to post
Share on other sites
or probably it''s just that he is in Projection-Matrix-Mode, and there coordinates are given INVERSED.
glMatrixMode(GL_PROJECTION);
glTranslatef(0.0f, 0.0f, -6.0f);
will translate towards the viewer.

the other posibility is that __they__ uses this:
glOrtho(-1, 1, -1, 1, -1, 1);
so you can only see things with -1 < x < 1; -1 < y < 1; -1 < z < 1 (homogenous space).
if you are in PROJECTION-matrix-mode and you reset it with glLoadIdentity() you should allways rebuild the projection-matrix via glOrtho or glFrustum/gluPerspective. Look into your tutorials for that.

to test in which matrixmode you are you can use
int i;
glGetIntegerv(GL_MATRIX_MODE, &i);
if( i == GL_MODELVIEW )
/*you are in modelview mode*/
else
/* you are in projection mode */


Share this post


Link to post
Share on other sites
Hi, and first I'm sorry, I've had a 'delay', so thanks everybody for posting. Some problems have been solved.

I have been trying to set up my concepts, and I've questions ... Let's see a bit of functions ->

glViewport(0,0,width,height);

This function, sets the "space" where OpenGL can write. The two initial zeros sets where OpenGL starts the view???.

gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.0f,100.0f);

Ok, this is easier ... the first are the vision & direction degrees. Then width/height sets the aspect ratio. The last values sets the max planes (near/far). Question , using gluPerspective, if we're over a window of 640x480 (640/480 = 1,33), Is -1.33 to 1.33 the maxium line that we can draw over the X axis?

And, the last question. For those who have read till this point my congratulations . Thats a strange effect. If I create a window (800,600 f.e), and set a text that is just in the corner of the window (That's the desired effect), if I resize the window (1024,768 in window) that texts moves a bit down in the window. Why?

I hope everybody understands me...and ... thanks for reading, always.

Greetings,
Jacob.

[edited by - jacob84 on July 30, 2003 5:06:39 PM]

Share this post


Link to post
Share on other sites
that''s because the viewport needs to be resetuped every time the window changes it''s size. the aspect ratio needs to be positive because it is a relation between the top and the right plane.
the distance to the near plane needs to be a nonzero value because you divide through it while z-testing.

Share this post


Link to post
Share on other sites