Main Menu

Quads again

Started by EricTheRed, September 09, 2003, 02:06:20

Previous topic - Next topic

EricTheRed

I hate to keep pestering everyone with questions, but I couldn't find any other resource that dealt with my problem, so...

I have a series of, say, 5 textured quads. I have them lined up and rotated 90 degrees such that only the side is showing, like so:

| | | | | ... rotated later to become [] [] [] [] []

The only problem is, in perspective mode, the quads farther away from the centre show some of the texture and not simply the edge. Is there any way to avoid this while still being able to rotate the quads on the y axis? Orthographic projection mode would do the trick, but then I can't rotate, so no help there. Any other ideas?

[I appologize if this seems a very naive question, but search was getting me nowhere, so...]

elias

Why can't you rotate in ortho mode?

- elias

jasonpai

hi,
you can rotate in ortho mode. in ortho mode the space remains the same, a three dimensional coordinate system. only the projection mode differs. in ortho mode this coordinate system is mapped without perspective. that means that parallel lines don't cross in infinity. in perspective mode they get closer to each other the farer away they are.

jason
 want something good to die for
to make it beautiful to live.
-[queens of the stone age]

EricTheRed

(Wow! I feel really stupid. Goes with the job, I suppose.  :P)

I suppose the fault lies in my understanding. I wasn't getting anything close to expected behavior using glRotatef in glOrtho mode, so I assumed that the two didn't mix for whatever reason. Anyhow, is the following behaviour normal for glOrtho mode? A textured quad shown with a rotation of 0.0f on all axes is drawn no problem, but as soon as I add any rotation not a multiple of 360 the quad "disappears". I can't see even part of the texture. Strange, yes? Below is my rendering code (multiple procedures in reality, but collated here for convenience), in case the fault somwhere in there. Help!
GL.glMatrixMode(GL.GL_PROJECTION);
GL.glLoadIdentity();
GL.glOrtho(0, 800, 0, 600, -1, 1);

GL.glMatrixMode(GL.GL_MODELVIEW);
GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
GL.glLoadIdentity();

GL.glRotatef(10.0f, 0.0f, 1.0f, 0.0f); //!!Works when comented!!
tex[i].bind();
drawTexturedQuad(100.0f, 100.0f, 128);
//Rendering ends

//Quad Code
private void drawTexturedQuad(float x, float y, int size) {
	GL.glBegin(GL.GL_QUADS);

	GL.glTexCoord2f(0.0f, 0.0f);
	GL.glVertex3f(x, y, 0.0f);

	GL.glTexCoord2f(0.0f, 1.0f);
	GL.glVertex3f(x, y + size, 0.0f);

	GL.glTexCoord2f(1.0f, 1.0f);
	GL.glVertex3f(x + size, y + size, 0.0f);

	GL.glTexCoord2f(1.0f, 0.0f);
	GL.glVertex3f(x + size, y, 0.0f);

	GL.glEnd();
}


Thanks for your patience with my less-than-very-intelligent questions!

- Eric

jasonpai

QuoteWow! I feel really stupid. Goes with the job, I suppose.
don't feel stupid, I needed some time to figure that out. (what have 2d gfx to do with a three dimensional space...? :wink: ) but now I feel very intelligent 8)
can't help you on your second problem, sorry.
 want something good to die for
to make it beautiful to live.
-[queens of the stone age]

elias

As I see it, you have two problems:

1. You glOrtho call has a way too small z axis range. You specify [-1, 1], you might want to try with [-200, 200] or something to make sure the rotated quad stays within the frustum.

2. Rotating an already translated quad is not going to work. What I mean i that you're already moving the quad by yourself to 100, 100 _before_ the rotation happens. Rotations is always relative to 0, 0 so that's why your quad disappear. Now, to fix it, you need to draw the quad like this:
 GL.glBegin(GL.GL_QUADS); 
 
   GL.glTexCoord2f(0.0f, 0.0f); 
   GL.glVertex3f(-size/2, -size/2, 0.0f); 
 
   GL.glTexCoord2f(0.0f, 1.0f); 
   GL.glVertex3f(-size/2, size/2, 0.0f); 
 
   GL.glTexCoord2f(1.0f, 1.0f); 
   GL.glVertex3f(size/2, size/2, 0.0f); 
 
   GL.glTexCoord2f(1.0f, 0.0f); 
   GL.glVertex3f(size/2, -size/2, 0.0f); 
 
   GL.glEnd();


and do the transformation like this:

GL.glMatrixMode(GL.GL_MODELVIEW); 
GL.glLoadIdentity(); 
GL.glTranslatef(x, y, 0.0f);
GL.glRotatef(angle, 0.0f, 1.0f, 0.0f);


That is, let OpenGL do both the translation and rotation.

- elias

EricTheRed

Excellent. Everything is working as I had originally planned. Thank you for bearing with my many questions.

In retrospect, I suppose the problems arose from not knowing exactly how OpenGL works. As well as randomly changing settings to acheive the desired effect has worked for other programs, it appears that a more ... "structured" approach is needed now. So, it seems like a red book is in my future (though should I wait for the 1.4 version? Argh!)

PlanetMongo

Well, I gather the 1.2 or 1.3 redbook is out for free somewhere on the internet, I suppose it wouldn't hurt to grab that for now and wait for the update.  I've got the 1.3 redbook and it's perfectly okay.  Of course, by okay I mean it sits really pretty on my bookshelf because I've just not had the time to pick it up and try doing anything with it.  :(  I really need to finish translating all of chman's tutorials, copy them to my USB keychain, and take them home with me to work with.  And the latest lwjgl, too.  :P
ife sucks, kill yourself.