Upgrading from SDL 1.2 to 1.3

Started by
10 comments, last by BigJim 14 years, 7 months ago
Hi, I've upgraded the version of SDL I'm been using for my project from 1.2 to 1.3(built from SVN head) and I've been having very strange problems with OpenGL textures: I'm using SDL_Image(also built from head) to load my textures itno SDL_surfaces and am then uploading them manually, but whatever I do they just appear white. I've been using gDEbugger to investigate this problem and it's showing that the textures are uploaded correctly and the opengl state is more or less identical to that of the previous working SDL 1.2 version. Has anyone else experienced anything similar with SDL 1.3? Cheers Jamie
Advertisement
I have messed around with SDL 1.3, but I haven't started using it seriously. If you want you could post a small example demonstrating this behaviour I could see if I can reproduce it on my machine.
Good idea! The following very rapid hack of my game's main.cpp does the same - gDEbugger shows the image fine, but the quad is entirely white:

// System includes#include <SDL.h>#include <SDL_opengl.h>	#include <SDL_video.h>void CalculateOrthoMatrix(){	// Set up orthographic 2D matrices	glMatrixMode(GL_PROJECTION);	glLoadIdentity();	glOrtho(		0.0f, 		480, 		320, 		0.0f,		-1.0f,		1.0f);		glMatrixMode(GL_MODELVIEW);	glLoadIdentity();}void InitSDL(){	// Initialise SDL    SDL_Init(SDL_INIT_EVERYTHING);		// Enable key repeats	SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);	// Set opengl parameters - double buffered 32 bit colour	SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);	SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);		SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 0);	SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);			// Create window	SDL_WindowID windowID = SDL_CreateWindow(NULL, 		SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 		480, 		320, 		SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);		// Loop through all renderers found	int rendererIndex = 0;	int numRenderers = SDL_GetNumRenderDrivers();	for(int r = 0; r < numRenderers; r++)	{		// Get driver info		SDL_RendererInfo rendererInfo;		SDL_GetRenderDriverInfo(r, &rendererInfo);		// If this is the opengl driver use this		if(strcmp(rendererInfo.name, "opengl") == 0)		{			rendererIndex = r;		}	} 	// Create renderer	SDL_CreateRenderer(windowID, rendererIndex, 0);	// Immediately pump events(this seems to be 	// Required for messageboxes to ever work	SDL_PumpEvents();	 	glClearColor(0.0, 0.0, 0.0, 0.0);	// Enable normal alpha blending	glEnable(GL_BLEND);	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);	glShadeModel(GL_FLAT);	glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);	// Get initial viewing matrices	CalculateOrthoMatrix();}int main(int argc, char* argv[]){		// Initialise SDL	InitSDL();	SDL_Surface *pImageFormatSurface = SDL_LoadBMP("test.bmp");		GLuint textureHandle;	glEnable(GL_TEXTURE_2D);		glGenTextures(1, &textureHandle);		glBindTexture(GL_TEXTURE_2D, textureHandle);		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, pImageFormatSurface->w, pImageFormatSurface->h, 0, GL_RGB, GL_UNSIGNED_BYTE, pImageFormatSurface->pixels);	SDL_FreeSurface(pImageFormatSurface);	// Main SDL event loop	bool shouldQuit = false;	while(!shouldQuit)	{		SDL_Event sdlEvent;		while(SDL_PollEvent(&sdlEvent) && !shouldQuit)		{			// Select what type of event's occured			switch(sdlEvent.type)			{ 				// Quit event				case SDL_QUIT:				{					shouldQuit = true;	// Sets quitting flag				}break;			}		}		// Clear depth and colour buffers		glClear(GL_COLOR_BUFFER_BIT);		glBegin(GL_QUADS);		glTexCoord2f(0.0f, 0.0f);		glVertex2f(0.0f, 0.0f);		glTexCoord2f(1.0f, 0.0f);		glVertex2f(480.0f, 0.0f);		glTexCoord2f(1.0f, 1.0f);		glVertex2f(480.0f, 320.0f);		glTexCoord2f(0.0f, 1.0f);		glVertex2f(0.0f, 320.0f);		glEnd();		SDL_RenderPresent();	}		// Quit SDL	SDL_Quit();	return 0;}
I don't have much time, but I can give you some hints.

Firstly, you are mixing SDL's new *Render* functions with raw OpenGL. I don't think this is really supported, I think if you want to use raw OpenGL you should use the SDL_GL_*() functions.

Take a look at the SDL test files for inspiration though, testgl2.c is particularly applicable I think. You can cut down that to the minimal code required to create and run an OpenGL program with the new API.
Hmm, that does make sense as the only thing that I can see which would explain the problem is that SDL's messing with the OpenGL state....I'll try switching to those functions and see what happens. Will they also work with OpenGL ES? I'm also targetting the iphone and that code basically came from the fireworks sample.
Quote:Original post by BigJim
Hmm, that does make sense as the only thing that I can see which would explain the problem is that SDL's messing with the OpenGL state....I'll try switching to those functions and see what happens. Will they also work with OpenGL ES? I'm also targetting the iphone and that code basically came from the fireworks sample.


I'm using SDL 1.3 on the iPhone and Windows without problems, instead of using glBegin/glEnd you can use VB= for instance. Basically is the same.

One question: Can SDL_Window window_id variable be local instead of class variable or global?

Thanks.
I've seen things you people wouldn't believe. Attack ships on fire off the shoulder of Orion. I watched C-beams glitter in the dark near the Tannhauser gate. All those moments will be lost in time, like tears in rain. Time to die.
Well, as SDL's written in C, SDL_Window won't have a destructor or anything so presumably you can do what you like with it :) How are you setting up your window/opengl context ricardo?
Hi,

I've taken test2.c and added texture loading to it and exactly the same thing seems to be happening...Did anyone try compiling my demo program?

Cheers

Jamie
Hi,

I've taken test2.c and added texture loading to it and exactly the same thing seems to be happening...Did anyone try compiling my demo program?

Cheers

Jamie
Hi,

I've taken test2.c and added texture loading to it and exactly the same thing seems to be happening...Did anyone try compiling my demo program?

Cheers

Jamie

This topic is closed to new replies.

Advertisement