Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Question from OpenGL and JOGL newbie.  (Read 1282 times)
0 Members and 1 Guest are viewing this topic.
Offline Addictman

Senior Member


Medals: 3
Projects: 1


Java games rock!


« Posted 2007-08-08 09:38:26 »

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:

1  
2  
3  
4  
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:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
   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 Smiley
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 Smiley
Offline gouessej
« Reply #1 - Posted 2007-08-08 13:37:09 »

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:

1  
2  
3  
4  
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:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
   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 Smiley
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 Smiley

glMatrixMode allow you to choose which matrix you wish to manipulate. Each matrix has a specific role. There are a matrix for the model view, an other matrix for the projection, an other matrix for the textures...

Offline Chris61182

Junior Member





« Reply #2 - Posted 2007-08-11 08:08:33 »

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.

For standard textures the coordinates do range from 0.0 to 1.0, but for texture rectangles they are integer values from 0 to texture size in that dimension. So yes 1 is literally one pixel/texel, and 2 would literally be two, and so on. Fortunately NPOTs (non-power of two textures) are being more and more ubiquitous and with both OpenGL 2.0 and beyond, and DX10 requiring support it shouldn't take too long.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CogWheelz (14 views)
2014-07-30 21:08:39

Riven (21 views)
2014-07-29 18:09:19

Riven (14 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (32 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (42 views)
2014-07-24 01:59:36

Riven (42 views)
2014-07-23 21:16:32

Riven (29 views)
2014-07-23 21:07:15

Riven (30 views)
2014-07-23 20:56:16
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!