Hi.
I am tampering with OpenGL and JOGL for the first time. I feel like I understand some of it, after some decent tutorials and such, but there is so much I do not understand.
Currently I am trying to to texture a 3D quad. (cube). Now I’ve looked through different examples, including those over at Nehe. There are some differences to my code that might or might not be the reason my “cube” looks nothing like a cube at all. (More like a 2D quad, and if I rotate it over x or y axiz, it looks totally garbled).
I am loading my texture through TextureIO:
TextureIO.setTexRectEnabled(true);
tex = TextureIO.newTexture( url, true, TextureIO.PNG);
tex.setTexParameteri(GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
tex.setTexParameteri(GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST);
I am using the TexRectEnabled and mipmap boolean to true because of the weird behaviour I get when loading textures not POW2. (White quad or nothing at all).
All the examples I see, render in the scope of -1 -> 1, 0r 0 -> 1 for 2D. I don’t know why, but while it seems 1.0f works as the value 100% in these examples, it works more like 1 pixel in my code.
In addition, after alot of try/fail, I found out that the texture when bound, was not where I expected it to be. TextureIO returns a texture that is obvioiusly different in some way, from the textures used in
for instance the Nehe tutorials.
for instance, my 2D quad is rendered like this:
gl.glBegin(GL.GL_QUADS);
{
TextureCoords tx = texture.getImageTexCoords();
gl.glTexCoord2f(tx.left(), tx.top());
gl.glVertex2f(0, 0);
gl.glTexCoord2f(tx.left(), tx.bottom());
gl.glVertex2f(0,ih);
gl.glTexCoord2f(tx.right(), tx.bottom());
gl.glVertex2f(iw,ih);
gl.glTexCoord2f(tx.right(), tx.top());
gl.glVertex2f(iw,0);
}
gl.glEnd();
And rendering of this 2D cube works well. (iw is ImageWidth of texture, and ih is ImageHeight). When I get to 3D though, I am lost
I see some differences from my code to the others, in the way that MatrixMode is set, and where it is set to what. And I admit, I dont know what the MatrixMode does