SDL+OpenGl-- prob.with texture mapping

Started by
2 comments, last by evillive2 16 years, 11 months ago
Hi! I must admit I am a bit uncertain whether this post should be under "Opengl" or "SDL", because my question is related to both APIs. I wanted to use SDL to load images/texture to use in Opengl; that is, I wanted to apply textures, that I have loaded in SDL, to my 3d-object in opengl. I do know how to load images in SDL and how to apply textures to an object in opengl, so what is my question then? Well, my question is: How do I "copy" an image loaded with the help of SDL to opengl(opengl and SDL are two "separate" APIs, aren`t they?)? I could of course use wiggle for this purpose, but I have no knowledge of wiggle at all.(or any WIN32-programming in general). I really hope you can give me some advice. I`m stuck
Advertisement
This is a difficult thing to do I have been working on solving this problem in my own graphics engine and it has taken several months to almost have it finished. My graphics engine is open source so feel free to copy how I am doing it but in the meen time i would start with this sdl to opengl faq it is a little out of date but has some good starting info

The most difficult part is supporting many different image file formats, render out images that are not in powers of two, and handling the fact that coordinate system that opengl uses is flipped from the one in sdl.

there is a code snip floating around that i am sure some will post that is a general way of doing it but I don't have it handy right now.

also the new version of sdl_gfx has a sdl surface to opengl texture function you mite look at to get an idea, and do a goolge search for sdl surface to opengl texture. You should come a cross a lot of good links

[Edited by - blackcloak on May 14, 2007 5:10:19 PM]
Black CloakEpee Engine.
This is what I've been using, and it's worked for me. I'm using SDL_Image, but the principle should be the same. This is for PNG's with an alpha channel by the way, I think the glTexImage2D call would be a little different if you were using something without an alpha channel.

SDL_Surface *image;int texture_id;glGenTextures(1, (GLuint*)&texture_id);image = IMG_Load(filename);if(image == NULL) {    printf("%s",SDL_GetError());    SDL_Quit();}glBindTexture(GL_TEXTURE_2D, texture_id);glTexImage2D(GL_TEXTURE_2D, 0, 4, image->w, image->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels);SDL_FreeSurface(image);
Take a look at the hxRender library. Even if you don't use it directly the source code is pretty helpful to get your head wrapped around this stuff.

hxRender library
Evillive2

This topic is closed to new replies.

Advertisement