Hello !
I’ve a very strange problem: when I use my functions to load textures before SDL_SetVideoMode and the init of the openGl context, it works fine.
But when I do it later it stops working :doh:
Could you give it a look please ?
(It’s the call to LoadMenu which fails, without error, just black screen)
int SetVideoMode() {
if( NULL == SDL_SetVideoMode(WINDOW_WIDTH, WINDOW_HEIGHT, 32, SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_RESIZABLE ) ) {
fprintf(stderr, "Can't open an SDL window
");
return 0;
}
return 1;
}
void InitGlContext() {
glViewport(0,0,WINDOW_WIDTH,WINDOW_HEIGHT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-1.,1.,-1.,1.);
}
int main( int argc, char* argv[] ) {
/* Init of the commands */
KeyboardState keyboard;
int i = 0;
while( i != SDLK_LAST )
keyboard.keys[i++] = 0;
/* Init of the SDL library */
if( -1 == SDL_Init(SDL_INIT_VIDEO) ){
fprintf(stderr, "Can't initialize the SDL library
");
return EXIT_FAILURE;
}
if( !SetVideoMode() )
return EXIT_FAILURE;
InitGlContext();
Menu menu = CreateMenu(8);
if( !LoadMenu(&menu,THEMES_DIRECTORY[0]) )
return EXIT_FAILURE;
Game game = CreateGame(2);
if( !InitGame(&game) )
return EXIT_FAILURE;
....
and the functions LoadMenu with CreateTexture:
Texture* CreateTexture(char* file) {
if( NULL == file ) {
fprintf(stderr,"Gived file path is NULL in CreateTexture
");
}
Texture* res = (Texture*)malloc(sizeof(Texture));
if( NULL == res) {
fprintf(stderr,"Can't create new texture
");
return NULL;
}
res->surface = IMG_Load(file);
if( NULL == res->surface ) {
fprintf(stderr,"Can't load the image %s
",file);
free(res);
return NULL;
}
glGenTextures(GL_TEXTURE_2D,&(res->id));
if( glGetError() != GL_NO_ERROR ) {
fprintf(stderr,"Can't gen the texture id
");
free(res);
SDL_FreeSurface(res->surface);
return NULL;
}
return res;
}
int LoadMenu(Menu* menu,char* directorypath) {
DIR* directory;
struct dirent* file;
char full_path[strlen(directorypath) + 255];
/* Getting of the menu images *************************************/
if(NULL == (directory = opendir(directorypath)) ) {
fprintf(stderr,"The theme %s can't be loaded
", directorypath);
return 0;
}
int index = 0;
while( NULL != (file = readdir(directory)) ) {
strcpy(full_path,directorypath);
strcat(full_path,"/");
strcat(full_path,file->d_name);
if( 0 == strcmp(file->d_name,"arkanopong.png") ) {
menu->items[index] = CreateMenuItem(
CreateBox(PointXY(-0.25,1),PointXY(0.25,1),PointXY(0.25,0.8),PointXY(-0.25,0.8)),
CreateTexture(full_path),
-1);
index++;
}
else if( 0 == strcmp(file->d_name,"1player.png") ) {
menu->items[index] = CreateMenuItem(
CreateBox(PointXY(-0.25,0.8),PointXY(0.25,0.8),PointXY(0.25,0.6),PointXY(-0.25,0.6)),
CreateTexture(full_path),
0.8);
index++;
}
else if( 0 == strcmp(file->d_name,"2players.png") ) {
menu->items[index] = CreateMenuItem(
CreateBox(PointXY(-0.25,0.6),PointXY(0.25,0.6),PointXY(0.25,0.4),PointXY(-0.25,0.4)),
CreateTexture(full_path),
2);
index++;
}
else if( 0 == strcmp(file->d_name,"3players.png") ) {
menu->items[index] = CreateMenuItem(
CreateBox(PointXY(-0.25,0.4),PointXY(0.25,0.4),PointXY(0.25,0.2),PointXY(-0.25,0.2)),
CreateTexture(full_path),
3);
index++;
}
else if( 0 == strcmp(file->d_name,"4players.png") ) {
menu->items[index] = CreateMenuItem(
CreateBox(PointXY(-0.25,0.2),PointXY(0.25,0.2),PointXY(0.25,0),PointXY(-0.25,0)),
CreateTexture(full_path),
4);
index++;
}
else if( 0 == strcmp(file->d_name,"5players.png") ) {
menu->items[index] = CreateMenuItem(
CreateBox(PointXY(-0.25,0),PointXY(0.25,0),PointXY(0.25,-0.2),PointXY(-0.25,-0.2)),
CreateTexture(full_path),
5);
index++;
}
else if( 0 == strcmp(file->d_name,"6players.png") ) {
menu->items[index] = CreateMenuItem(
CreateBox(PointXY(-0.25,-0.2),PointXY(0.25,-0.2),PointXY(0.25,-0.4),PointXY(-0.25,-0.4)),
CreateTexture(full_path),
6);
index++;
}
else if( 0 == strcmp(file->d_name,"switchtheme.png") ) {
menu->items[index] = CreateMenuItem(
CreateBox(PointXY(-0.25,-0.4),PointXY(0.25,-0.4),PointXY(0.25,-0.6),PointXY(-0.25,-0.6)),
CreateTexture(full_path),
0);
index++;
}
}
if( index < menu->nb_items ) {
fprintf(stderr,"Missing menu images, only %d
",index);
return 0;
}
closedir(directory);
return 1;
}
Thanks in advance for your help, I’m stuck :tired: