I am trying to use some code I have used some time ago and render using opengl but now the result is nothing viewable.
Can anyone please tell me what is wrong in thes code?
- Code: Select all
void renderSprite(Csprite sprite, bool androidUseQuads = false)
{
glEnable(GL_TEXTURE_2D);
// position
glTranslatef(sprite.x, sprite.y, sprite.z);
glBindTexture(GL_TEXTURE_2D, sprite.texture.id);
/* Start Transformations */
glTranslatef((float)sprite.w / 2, (float)sprite.h / 2, 0);
// rotation
glRotatef(sprite.angleX, 1.0f, 0.0f, 0.0f);
glRotatef(sprite.angleY, 0.0f, 1.0f, 0.0f);
glRotatef(sprite.angleZ, 0.0f, 0.0f, 1.0f);
// scale
glScalef(sprite.scaleX, sprite.scaleY, sprite.scaleZ);
glTranslatef((float)-1 * sprite.w / 2, (float)-1 *sprite.h / 2, 0);
/* End Transformations */
// calculate mapping vertexes
float minX = (float)sprite.srcX / (float)sprite.texture.w * sprite.texture.p2w;
float maxX = ((float)sprite.srcX + (float)sprite.w) / (float)sprite.texture.w * sprite.texture.p2w;
float minY = (float)sprite.srcY / (float)sprite.texture.h * sprite.texture.p2h;
float maxY = ((float)sprite.srcY + (float)sprite.h) / (float)sprite.texture.h * sprite.texture.p2h;
float tmp;
if(sprite.flipX)
{
tmp = minX;
minX = maxX;
maxX = tmp;
}
if(sprite.flipY)
{
tmp = minY;
minY = maxY;
maxY = tmp;
}
/* The following piece of code is deprecated ¿? */
#if 0
{
int rect[4] = {sprite.srcX, sprite.srcY + sprite.h, sprite.w, -sprite.h};
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, rect);
float spriteX = sprite.x;
float spriteY = SCREEN_HEIGHT - sprite.y - sprite.h;
float spriteW = sprite.w * sprite.scaleX;
float spriteH = sprite.h * sprite.scaleY;
spriteX = spriteX + (sprite.w / 2 - spriteW / 2);
spriteY = spriteY + (sprite.h / 2 - spriteH / 2);
glDrawTexiOES(spriteX, spriteY, 0, spriteW, spriteH);
}
#endif
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
GLfloat vertices[] = { 0.0f, 0.0f, 0.0f, sprite.w, 0.0f, 0.0f,
sprite.w, sprite.h, 0.0f, 0.0f, sprite.h, 0.0f };
GLfloat texcoords[] = { minX, minY, maxX, minY, maxX, maxY, minX, maxY };
glVertexPointer(3, GL_FLOAT, 0, vertices);
glTexCoordPointer(2, GL_FLOAT, 0, texcoords);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glLoadIdentity();
}
Here is the initialization:
- Code: Select all
#define SCREEN_WIDTH 800
#define SCREEN_HEIGHT 480
#define SCREEN_BPP 16
#define TRUE 1
#define FALSE 0
SDL_Surface *screen;
int initGL(void)
{
glClearColor(0, 0, 0, 0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glEnable(GL_TEXTURE_2D);
glEnable(GL_ALPHA_TEST);
glEnable(GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glAlphaFunc(GL_GREATER, 0.01);
#ifndef ANDROID
#define glOrthof glOrtho
#endif
glOrthof(0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
if(glGetError() != GL_NO_ERROR)
return(FALSE);
else
return(TRUE);
}
void initSDL()
{
int videoFlags;
const SDL_VideoInfo *videoInfo;
if(SDL_Init( SDL_INIT_VIDEO | SDL_INIT_AUDIO ) < 0)
{
fprintf( stderr, "Video initialization failed: %s\n", SDL_GetError());
exit(-1);
}
videoInfo = SDL_GetVideoInfo( );
if(!videoInfo)
{
fprintf(stderr, "Video query failed: %s\n", SDL_GetError());
exit(-1);
}
videoFlags = SDL_OPENGL; /* Enable OpenGL in SDL */
videoFlags |= SDL_GL_DOUBLEBUFFER; /* Enable double buffering */
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, videoFlags);
if (!screen)
{
fprintf(stderr, "Video mode set failed: %s\n", SDL_GetError());
exit(-1);
}
Mix_OpenAudio(44100, AUDIO_S16SYS, 2, 2048);
SDL_WM_SetCaption( "Dragon Memory", "Dragon Memory");
SDL_WM_SetIcon(IMG_Load(DATADIR "/gfx/icon.p"), NULL);
}
Any help ir appreciated

Thanks


