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 (535)
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  
  [SOLVED] Texturing VBOs  (Read 1813 times)
0 Members and 1 Guest are viewing this topic.
Offline Giovanni

Junior Member




chop!


« Posted 2012-05-23 20:05:42 »

I don't seem to understand how texturing works for VBOs. It was easy back then when I used immediate mode (glTexCoord2f ...) but you can of course not apply the same to VBOs.

I do know that you need to create own buffers / add the texture coordinates to a buffer but I can not really figure out how these coordinates actually work / look like. When I used immediate mode it was a little bit like this:

1  
2  
3  
4  
5  
glBindTexture( ... );

glTexCoord2f(1f,0);
glVertex2d(x + 50, y);
// ...


I guess that I can also use TEXTURE_2D in this case.

This is what I got in my vertex buffer (just the normal buffer which contains the coordinates of my quad):

1  
-0.5f,-0.5f, 0f,   0.5f,-0.5f,0f,      0.5f,0.5f,0f,   -0.5f,0.5f,0f

(Yes, the quads are visible so there shouldn't be any problem)

My questions now are:
  • How would the texture coordinates for this quad look like(This all happens in 3D - space)?
  • At which place do I have to call glBindTexture( ... )?


I do know that you need following piece of code to enable texture coordinates:
1  
2  
3  
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboTextureHandle);
glTexCoordPointer(3, GL_FLOAT, 0, 0);



Thanks in advance.



Note:


I have used the search function but I couldn't find anything that helped me out.
Offline sproingie

JGO Kernel


Medals: 202



« Reply #1 - Posted 2012-05-23 20:51:44 »

Quote
   How would the texture coordinates for this quad look like(This all happens in 3D - space)?

Same as texture coords in immediate mode: two-dimensional, between 0.0 and 1.0 inclusively, assuming you have a 2d texture. 

Quote
   At which place do I have to call glBindTexture( ... )?

Any time before you draw it.

Silly question: you did enable textures, right? And you don't have a fragment shader otherwise taking over texturing?

Offline matheus23

JGO Kernel


Medals: 106
Projects: 3


You think about my Avatar right now!


« Reply #2 - Posted 2012-05-23 21:10:46 »

Maybe your problem is, that you don't quite understand, how to "store" these Texture coords.

There are 2 ways:

 - use 2 VBOs, one for Vertices and one for Texture coords (good for starting up with em):
 call glTextureCoordPointer just like the vertex pointer, but with the other VBO and buffer.

 - use 1 "Interleaved" VBO (like written in the bottom of the article on the lwjgl wiki), where the buffer looks like this:
 
1  
(vertices) -0.5, 0.5, 0.5 (textureCoords) 0.0, 0.0 (vertices) 0.0, 0.0, 0.0 (textureCoords) 1.0, 0.0 ...

Then you would need to operate with the offsets and the "stride".

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Giovanni

Junior Member




chop!


« Reply #3 - Posted 2012-05-23 21:27:29 »

I do understand how to use them and that I have to store them in a VBO. And yes, I did enable TEXTURE_2D. My main problem however is that I don't exactly understand what the float values ranging from 0.0 - 1.0 mean.

Would the coordinates for this quad

1  
-0.5f,-0.5f, 0f,   0.5f,-0.5f,0f,      0.5f,0.5f,0f,   -0.5f,0.5f,0f


look like this?:

1  
0f,0f,    1f, 0f,      1f,1f      0f, 1f
Offline Giovanni

Junior Member




chop!


« Reply #4 - Posted 2012-05-23 21:52:42 »

I have just found the problem. The size of the TexCoordPointer was 3 instead of 2. Stupid mistake I guess.
Anyway, thanks for the quick help!
Offline davedes
« Reply #5 - Posted 2012-05-23 21:59:52 »

If you're making a 2D game, it would be easier to specify vertex positions in 2D orthographic screen space, for e.g. (0, 0) being top left, rather than world space.

You might like to read up on texturing a bit, as it's not always as simple as just using 0.0 or 1.0. (i.e. for sprite atlases, or non-power-of-two images packed in a power-of-two-texture, or what have you).
http://www.arcsynthesis.org/gltut/Texturing/Texturing.html

And since you're already learning modern techniques, IMO you should try learning pure OpenGL 3+ ways of doing things (i.e. custom GLSL attributes and glVertexAttribPointer instead of glTexCoordPointer).

Offline Giovanni

Junior Member




chop!


« Reply #6 - Posted 2012-05-23 22:40:06 »

I am actually playing around a little bit with 3D games. Thanks for the link, I kinda knew that it can't always just be 1 or 0, eventhough it works now.

About using OpenGL 3+: I heard that it is not supported by most of the older computers, what is of course not what I want. If I create games, I want them to be available for a wide range of players. Anyway, GLSL seems to be quite interesting and I will for sure take a look at them later, but currently I want to 'fix' my knowledge with normal VBOs.
Offline davedes
« Reply #7 - Posted 2012-05-23 22:59:01 »

If your target supports VBOs, there is a very good chance it will also support shaders. The code for binding and setting up a shader looks the same; the only difference is that you're using custom attributes ("a_Texcoord0") instead of builtins ("gl_MultiTexCoord0"). The best way to "fix" your knowledge of VBOs is to learn how to use them without relying on deprecated code. Smiley

Offline Giovanni

Junior Member




chop!


« Reply #8 - Posted 2012-05-23 23:02:19 »

Oh, I didn't know that. I will take a close look into them asap. Thanks for clearing me up!
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.

Riven (9 views)
2014-07-29 12:53:52

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

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

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

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

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

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

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21

Zero Volt (51 views)
2014-07-17 23:47:54
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!