Applying a texture to a vertex array
2 posters
Applying a texture to a vertex array
Hello,
I've been working on a game that involves procedural generated levels. This means I can't use blender for world creation, so I'm creating the levels as vertex arrays (I guess I should move to VBOs, on the future?). I'm kinda new to OpenGL, too, so pardon me if I say something wrong.
So, even though OpenGL ES is a subset of OpenGL, some things like texture mapping should work more or less the same way, right? So, I started coding on Ubuntu, then moved to OSX. The vertex creation code worked without a hitch, but I hadn`t much luch with texturing. While the texture did show on Ubuntu, it didn`t on OSX. Obviously, I had to adapt my code to use SIO2's resource loading scheme, and I guess that's where my mistake is.
I loaded the texture with:
"floorTexture" is a SIO2Image*. "dirt.jpg" is a 128x128 texture in the Resources folder, as well.
See those two "glTexParameter" calls tucked in there? It was a shameless hack attempt to make SIO2 render wrapped textures. I wandered through the sio2ImageLoad method code, and it didn't check for the wrap flags, so I've set them myself. I don't know if it worked, since no texture is rendered at all.
Then, I rendered the vertex array with:
The vertexes are correctly displayed, but without texture. You can see I reused the vertex array as the texture coord array. It worked on linux, but I'm not sure about it, too. I've also tried using sio2ImageRender.
So, what do you think I could have done wrong? I've already searched the forum, with no luck, too =/
Thanks in advance for your help!
I've been working on a game that involves procedural generated levels. This means I can't use blender for world creation, so I'm creating the levels as vertex arrays (I guess I should move to VBOs, on the future?). I'm kinda new to OpenGL, too, so pardon me if I say something wrong.
So, even though OpenGL ES is a subset of OpenGL, some things like texture mapping should work more or less the same way, right? So, I started coding on Ubuntu, then moved to OSX. The vertex creation code worked without a hitch, but I hadn`t much luch with texturing. While the texture did show on Ubuntu, it didn`t on OSX. Obviously, I had to adapt my code to use SIO2's resource loading scheme, and I guess that's where my mistake is.
I loaded the texture with:
- Code:
SIO2stream* _SIO2stream = sio2StreamOpen( "dirt.jpg", 1 );
if( _SIO2stream )
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
floorTexture = sio2ImageInit( "dirt.jpg" );
{
sio2ImageLoad( floorTexture, _SIO2stream );
sio2ImageGenId( floorTexture, NULL, 0.0f );
}
_SIO2stream = sio2StreamClose( _SIO2stream );
}
"floorTexture" is a SIO2Image*. "dirt.jpg" is a 128x128 texture in the Resources folder, as well.
See those two "glTexParameter" calls tucked in there? It was a shameless hack attempt to make SIO2 render wrapped textures. I wandered through the sio2ImageLoad method code, and it didn't check for the wrap flags, so I've set them myself. I don't know if it worked, since no texture is rendered at all.
Then, I rendered the vertex array with:
- Code:
sio2WindowEnter2D( sio2->_SIO2window, 0.0f, 1.0f );
{
glVertexPointer(2, GL_FLOAT, 0, vertexes);
glEnableClientState( GL_VERTEX_ARRAY );
glTexCoordPointer(2, GL_FLOAT, 0, vertexes);
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors);
glEnableClientState( GL_COLOR_ARRAY );
glBindTexture(GL_TEXTURE_2D, floorTexture->tid);
glPushMatrix();
{
glDrawArrays(GL_TRIANGLES, 0, numVertexes);
}
glPopMatrix();
}
sio2WindowLeave2D();
The vertexes are correctly displayed, but without texture. You can see I reused the vertex array as the texture coord array. It worked on linux, but I'm not sure about it, too. I've also tried using sio2ImageRender.
So, what do you think I could have done wrong? I've already searched the forum, with no luck, too =/
Thanks in advance for your help!
Pixel- Posts : 3
Join date : 2009-03-23
Re: Applying a texture to a vertex array
Are you sure textures are enabled? Are you sure your objects are winding the right way?
Just a couple of shots in the dark...
-j
Just a couple of shots in the dark...
-j
meteors- Posts : 241
Join date : 2008-11-08
Location : Sunny Florida
Re: Applying a texture to a vertex array
meteors wrote:Are you sure textures are enabled? Are you sure your objects are winding the right way?
Just a couple of shots in the dark...
-j
The vertex array's points are on counter-clockwise orientation. When I inverted them to clockwise, the vertexes weren't displayed. I've tried creating a separate array for clockwise texture coordinates (so I had ccwise for vertexes and cwise for texture coords), but it also didn't work.
I also enabled texturing during the render loop:
- Code:
sio2WindowEnter2D( sio2->_SIO2window, 0.0f, 1.0f );
{
glEnable(GL_TEXTURE_2D);
// Standard GL calls...
glVertexPointer(2, GL_FLOAT, 0, vertexes);
glEnableClientState( GL_VERTEX_ARRAY );
glTexCoordPointer(2, GL_FLOAT, 0, texcoords);
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors);
glEnableClientState( GL_COLOR_ARRAY );
glBindTexture(GL_TEXTURE_2D, floorTexture->tid);
glPushMatrix();
{
glDrawArrays(GL_TRIANGLES, 0, floors * 6);
}
glPopMatrix();
}
sio2WindowLeave2D();
No luck =(
Gonna keep trying...
Pixel- Posts : 3
Join date : 2009-03-23
Yay!
It worked!
It was a very, very basic mistake. When I downloaded the texture, it was -huge- (1200x1000, I guess) and also not a power of 2, so I resized it to 128. Well, at least I thought I did.
I guess you already know where I'm go to =]
By the way, I did have to create a separate array for texture coordinates. The values are the same from the vertex array, but divided by 100, or else the texture would look stretched.
Thanks!
It was a very, very basic mistake. When I downloaded the texture, it was -huge- (1200x1000, I guess) and also not a power of 2, so I resized it to 128. Well, at least I thought I did.
I guess you already know where I'm go to =]
By the way, I did have to create a separate array for texture coordinates. The values are the same from the vertex array, but divided by 100, or else the texture would look stretched.
Thanks!
Pixel- Posts : 3
Join date : 2009-03-23
Re: Applying a texture to a vertex array
Nice :-)
-j
-j
meteors- Posts : 241
Join date : 2008-11-08
Location : Sunny Florida
Similar topics
» Error after applying texture
» Programatically applying a texture
» Draw font to texture or render to texture possible?
» sio2FontPrint should disable color/normal array
» applying to textrue to non-uniform 3D model
» Programatically applying a texture
» Draw font to texture or render to texture possible?
» sio2FontPrint should disable color/normal array
» applying to textrue to non-uniform 3D model
Permissions in this forum:
You cannot reply to topics in this forum