Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (604)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (653)
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 2196 times)
0 Members and 1 Guest are viewing this topic.
Offline Giovanni

Junior Devvie


« Posted 2012-05-23 18: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:

glBindTexture( ... );

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):

-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:
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboTextureHandle);
glTexCoordPointer(3, GL_FLOAT, 0, 0);

Thanks in advance.


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 18:51:44 »

   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. 

   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: 122
Projects: 3

You think about my Avatar right now!

« Reply #2 - Posted 2012-05-23 19: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:
(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 Devvie


« Reply #3 - Posted 2012-05-23 19: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

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

look like this?:

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

Junior Devvie


« Reply #4 - Posted 2012-05-23 19: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 19: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).

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 Devvie


« Reply #6 - Posted 2012-05-23 20: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 20: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 Devvie


« Reply #8 - Posted 2012-05-23 21: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.

SHC (28 views)
2015-08-01 03:58:20

Jesse (20 views)
2015-07-29 04:35:27

Riven (40 views)
2015-07-27 16:38:00

Riven (21 views)
2015-07-27 15:35:20

Riven (24 views)
2015-07-27 12:26:13

Riven (14 views)
2015-07-27 12:23:39

BurntPizza (36 views)
2015-07-25 00:14:37

BurntPizza (46 views)
2015-07-24 22:06:39

BurntPizza (31 views)
2015-07-24 06:06:53

NoxInc (37 views)
2015-07-22 22:16:53
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 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‑
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!