OpenGL Code Question
5 posters
OpenGL Code Question
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
Re: OpenGL Code Question
Did you enable vertex array and tex coord array?
oioioi- Posts : 136
Join date : 2008-12-02
Location : Norway
Re: OpenGL Code Question
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
Re: OpenGL Code Question
Try replacing
glBindTexture( GL_TEXTURE_2D, _p->_SIO2material->_SIO2image[ 0 ]->tid );
with
sio2MaterialRender(_p->_SIO2material);
that's what I used
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
Re: OpenGL Code Question
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
Re: OpenGL Code Question
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.
Just replace your render code with the appropriate VBO equivalent.
freebird373- Posts : 10
Join date : 2008-11-21
Re: OpenGL Code Question
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.
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
Re: OpenGL Code Question
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...
Similar topics
» Newbie question, code signing error when trying to run tutorial1
» SIO2 and iPhone OS 3.0
» Create primitives
» OpenGL Combiner
» OpenGL ES Trace
» SIO2 and iPhone OS 3.0
» Create primitives
» OpenGL Combiner
» OpenGL ES Trace
Permissions in this forum:
You cannot reply to topics in this forum
|
|