You can follow this site for SDL tutorials http://www.lazyfoo.net/SDL_tutorials/http://www.lazyfoo.net/SDL_tutorials/
And tutorial number 36 is what you need http://www.lazyfoo.net/SDL_tutorials/lesson36/index.php
But in this tutorial no opengl texturing is done, so I have added texture mapping component from your gpwiki link, so that you that you have a basic idea of how to do. I am showing you where to change what,
1. Declare a global textuer object like this
GLuint texture ; // Texture object handle
2. Add the following code in initGL()
SDL_Surface *surface; // Gives us the information to make the texture
if ( (surface = SDL_LoadBMP("image.bmp")) ) {
// Check that the image's width is a power of 2
if ( (surface->w & (surface->w - 1)) != 0 ) {
printf("warning: image.bmp's width is not a power of 2\n");
}
// Also check if the height is a power of 2
if ( (surface->h & (surface->h - 1)) != 0 ) {
printf("warning: image.bmp's height is not a power of 2\n");
}
// Have OpenGL generate a texture object handle for us
glGenTextures( 1, &texture );
// Bind the texture object
glBindTexture( GL_TEXTURE_2D, texture );
// Set the texture's stretching properties
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
// Edit the texture object's image data using the information SDL_Surface gives us
glTexImage2D( GL_TEXTURE_2D, 0, 3, surface->w, surface->h, 0,
GL_BGR, GL_UNSIGNED_BYTE, surface->pixels );
}
else {
printf("SDL could not load image.bmp: %s\n", SDL_GetError());
SDL_Quit();
return 1;
}
// Free the SDL_Surface only if it was successfully created
if ( surface ) {
SDL_FreeSurface( surface );
}
glViewport( 0, 0, 640, 480 );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho( 0, 640, 480, 0, -1, 1 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glEnable( GL_TEXTURE_2D );
//Initialize clear color
glClearColor( 0.f, 0.f, 0.f, 1.f );
3. Draw the quad in render function
// Bind the texture to which subsequent calls refer to
glBindTexture( GL_TEXTURE_2D, texture );
glBegin( GL_QUADS );
// Top-left vertex (corner)
glTexCoord2i( 0, 0 );
glVertex3f( 100, 100, 0 );
// Bottom-left vertex (corner)
glTexCoord2i( 1, 0 );
glVertex3f( 228, 100, 0 );
// Bottom-right vertex (corner)
glTexCoord2i( 1, 1 );
glVertex3f( 228, 228, 0 );
// Top-right vertex (corner)
glTexCoord2i( 0, 1 );
glVertex3f( 100, 228, 0 );
glEnd();
4. Delete your textures in clean_up()
glDeleteTextures( 1, &texture );
Sorry I totally missed your questions
1. I've noticed a sudden drop of FPS since the tryout change (only the tiles are being rendered at the
moment since haven't made it global yet). The drop if from 400+ FPS to around 60 FPS after i use glDeleteTextures(); on the texture I've just drawn. Why is this? I suspect it's the conversion that drains the fps.
It's because creating and deleting texture is expensive operation, so you should only create a texture once and delete once you about to close your program or dont want to use that texture again.
2. If it is the conversion that drains the FPS, then it is smarter to convert the image once just as it loads and save the texture in the array instead of the surface? Sounds like it...
Yes, there is, the global you declared is the identifier for that image, its GLuint, so to create more textuer you need an array , like
Gluint texture [5] // this will hold 5 texture for you
Changes in InitGL()
// then you have to change to following where i = 0, 1 , 2 , 3 , 4
glGenTextures( 1, &texture[i] );
glBindTexture( GL_TEXTURE_2D, texture[i] );
3. Is there any reason for me to save the image as a SDL_Surface instead of loading it from OpenGL directly? Can i do that?
Yes, the above way shows you how to convert your SDL_Surface to opengl texture for later use, you need to convert each image exactly once.
4. If there is no reason at all for me to involve SDL in the rendering process then how to i keep track of the loaded image width and height? Right now i use surface->w/surface->h. Is there similar ways in OpenGl?
You have to write a bit of code, for this, you can create a class or struct that will hold the image information for you, like image width, height, image_id and other information.
I am just a learner so tried you help you, hope this helps