FORUM CLOSED, PLEASE REGISTER AT FORUM.SIO2INTERACTIVE.COM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Applying a texture to a vertex array

2 posters

Go down

Applying a texture to a vertex array Empty Applying a texture to a vertex array

Post  Pixel Sat Mar 28, 2009 3:47 pm

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:

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

Back to top Go down

Applying a texture to a vertex array Empty Re: Applying a texture to a vertex array

Post  meteors Sat Mar 28, 2009 4:09 pm

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
meteors
meteors

Posts : 241
Join date : 2008-11-08
Location : Sunny Florida

Back to top Go down

Applying a texture to a vertex array Empty Re: Applying a texture to a vertex array

Post  Pixel Sat Mar 28, 2009 5:23 pm

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

Back to top Go down

Applying a texture to a vertex array Empty Yay!

Post  Pixel Sat Mar 28, 2009 5:50 pm

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!

Pixel

Posts : 3
Join date : 2009-03-23

Back to top Go down

Applying a texture to a vertex array Empty Re: Applying a texture to a vertex array

Post  meteors Sat Mar 28, 2009 6:17 pm

Nice :-)


-j
meteors
meteors

Posts : 241
Join date : 2008-11-08
Location : Sunny Florida

Back to top Go down

Applying a texture to a vertex array Empty Re: Applying a texture to a vertex array

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum