Jump to content
  • Advertisement
Sign in to follow this  
crunch

SDL+OpenGl-- prob.with texture mapping

This topic is 4053 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!