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.

OpenGL Code Question

5 posters

Go down

OpenGL Code Question Empty OpenGL Code Question

Post  uprise78 Sun Mar 29, 2009 11:53 pm

Can anyone point me in the right direction as to why this crashes on the last line? I get a bad access error and can't for the life of me figure out why...

Code:

glPushMatrix();
         float _maxT = 1.0;
         float _maxS = 1.0;
         float _width = _p->_SIO2material->_SIO2image[ 0 ]->width;
         float _height = _p->_SIO2material->_SIO2image[ 0 ]->height;
         
         vec2 *point = sio2Vec2Init();
         point->x = _p->_SIO2transform->loc->x;
         point->y = _p->_SIO2transform->loc->y;
         
         GLfloat      coordinates[] = { 0.0f,   _maxT,
            _maxS,   _maxT,
            0.0f,   0.0f,
         _maxS,   0.0f };
         GLfloat      width = (GLfloat)_width * _maxS,
         height = (GLfloat)_height * _maxT;
         
         GLfloat      vertices[] = {   -width / 2 + point->x,   -height / 2 + point->y,   0.0f,
            width / 2 + point->x,   -height / 2 + point->y,   0.0f,
            -width / 2 + point->x,   height / 2 + point->y,   0.0f,
         width / 2 + point->x,   height / 2 + point->y,   0.0f };
         
         glEnable(GL_TEXTURE_2D);
         glBindTexture(GL_TEXTURE_2D, _p->_SIO2material->_SIO2image[ 0 ]->tid );
         glVertexPointer(3, GL_FLOAT, 0, vertices);
         glTexCoordPointer(2, GL_FLOAT, 0, coordinates);
         glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

uprise78

Posts : 228
Join date : 2008-10-31

Back to top Go down

OpenGL Code Question Empty Re: OpenGL Code Question

Post  oioioi Mon Mar 30, 2009 5:53 am

Did you enable vertex array and tex coord array?

oioioi

Posts : 136
Join date : 2008-12-02
Location : Norway

Back to top Go down

OpenGL Code Question Empty Re: OpenGL Code Question

Post  uprise78 Mon Mar 30, 2009 9:37 am

Tried enabling both vertex array and tex coord array and it sill crashes on the glDrawArrays command... below is the code for the segment:

Code:

      glPushMatrix();
      {         
         sio2TransformApply( _p->_SIO2transform );

         // Setup state
         glEnableClientState( GL_VERTEX_ARRAY );
         glEnableClientState( GL_TEXTURE_COORD_ARRAY );
         glEnable( GL_TEXTURE_2D );
         glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
         
         // START DRAW TEXTURE
            float _maxT = 1.0;
            float _maxS = 1.0;
            float _width = _p->_SIO2material->_SIO2image[ 0 ]->width;
            float _height = _p->_SIO2material->_SIO2image[ 0 ]->height;
            
            vec2 *point = sio2Vec2Init();
            point->x = _p->_SIO2transform->loc->x;
            point->y = _p->_SIO2transform->loc->y;
            
            GLfloat      coordinates[] = { 0.0f,   _maxT,
                                 _maxS,   _maxT,
                                 0.0f,   0.0f,
                                 _maxS,   0.0f };
            GLfloat      width = (GLfloat)_width * _maxS,
            height = (GLfloat)_height * _maxT;
            
            GLfloat      vertices[] = {   -width / 2 + point->x,   -height / 2 + point->y,   0.0f,
                                 width / 2 + point->x,   -height / 2 + point->y,   0.0f,
                                 -width / 2 + point->x,   height / 2 + point->y,   0.0f,
                                 width / 2 + point->x,   height / 2 + point->y,   0.0f };

            glBindTexture( GL_TEXTURE_2D, _p->_SIO2material->_SIO2image[ 0 ]->tid );
            glVertexPointer( 3, GL_FLOAT, 0, vertices );
            glTexCoordPointer( 2, GL_FLOAT, 0, coordinates );
            glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );
         // END DRAW TEXTURE
         
         // Undo Setup
         glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
         glDisable( GL_TEXTURE_2D);
         glDisableClientState(GL_VERTEX_ARRAY );
         glDisableClientState( GL_TEXTURE_COORD_ARRAY );

      }
      glPopMatrix();

uprise78

Posts : 228
Join date : 2008-10-31

Back to top Go down

OpenGL Code Question Empty Re: OpenGL Code Question

Post  oioioi Mon Mar 30, 2009 11:06 am

Try replacing
glBindTexture( GL_TEXTURE_2D, _p->_SIO2material->_SIO2image[ 0 ]->tid );
with
sio2MaterialRender(_p->_SIO2material);
that's what I used

oioioi

Posts : 136
Join date : 2008-12-02
Location : Norway

Back to top Go down

OpenGL Code Question Empty Re: OpenGL Code Question

Post  uprise78 Mon Mar 30, 2009 11:12 am

Changing the bind call to sio2MaterialRender or even commenting out the bindTexture call altogether still causes a crash on the glDrawArrays() call. If only openGL threw exceptions....

uprise78

Posts : 228
Join date : 2008-10-31

Back to top Go down

OpenGL Code Question Empty Re: OpenGL Code Question

Post  freebird373 Thu Apr 02, 2009 8:38 pm

It looks like your trying to use Vertex Arrays. SIO2 uses VBOs and you can't mixed VAs with VBOs.

Just replace your render code with the appropriate VBO equivalent.

freebird373

Posts : 10
Join date : 2008-11-21

Back to top Go down

OpenGL Code Question Empty Re: OpenGL Code Question

Post  uprise78 Thu Apr 02, 2009 8:54 pm

I figured it out. I just had to clear the vertex buffer before proceeding. I will post the code probably tomorrow for anyone interested. I put together a 2d game helper pack (or at least the start of one).

It currently has support for:
- layers
- sprites
- sprite children
- animations (multiple named animations per sprite)
- sprite actions (fadeTo, moveTo, rotateTo, scaleTo all reversible and with easing functions)
- image cache so you dont have to load images more than once for your sprites

There are still some things that need to be added but it should be more than sufficient to get going with a 2d game using SIO2. I'm not sure if SIO2Interactive wants to put it in the engine or not so I made it fully standalone. It doesn't require changing any of the SIO2 source and it uses it's own resource manager.

uprise78

Posts : 228
Join date : 2008-10-31

Back to top Go down

OpenGL Code Question Empty Re: OpenGL Code Question

Post  Francescu Thu Apr 02, 2009 11:15 pm

^^^^ Sounds neat Uprise ;-)

Francescu

Posts : 136
Join date : 2009-03-18

Back to top Go down

OpenGL Code Question Empty Re: OpenGL Code Question

Post  sio2interactive Thu Apr 02, 2009 11:33 pm

uprise78: Simply send me a template project showing me the capabilities of what you have done, make sure that the demo is complete enough to give me a good idea...
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 45
Location : Shanghai

http://sio2interactive.com

Back to top Go down

OpenGL Code Question Empty Re: OpenGL Code Question

Post  uprise78 Fri Apr 03, 2009 4:48 pm


uprise78

Posts : 228
Join date : 2008-10-31

Back to top Go down

OpenGL Code Question Empty Re: OpenGL Code Question

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