c++ - SDL_surface to OpenGL texture -
Hey, I have this script to load SDL_Surface and save it as OpenGL texture:
Code> Typingfill Glitter Texture; Texture load_text (std :: string fname) {SDL_Surface * tex_surf = IMG_Load (fname.c_str ()); If (! Tex_surf) {return 0; } Textured writ; Globe Texture (1, End Wit); GLBINNET (GL_TEXTURE_2D, WIT); GlTexImage2D (GL_TEXTURE_2D, 0, 3, tex_surf-> w, tex_surf- & gt; H, 0, GL_RGB, GL_UnSIGNED_BYTE, tex_surf- & gt; Pixels); GlTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); GlTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); SDL_FreeSurface (tex_surf); Return writ; }
The problem is that it is not working. When I call the function from the main function, it does not load any image (only the drawing color is changing while displaying it), and the program crashes when calling from any function outside the main function. This is the line that makes the program crashes:
2D (GL_TEXTURE_2D, 0, 3, tex_surf-> W, tex_surf-> H, 0, GL_RGB, GL_UnSIGNED_BYTE, tex_surf- & Gt; pixels);Can anyone see a mistake in this?
My condition is that you need to change SDL_Surface before trying to enter it in the OpenGL texture here Something that should give you a general idea:
SDL_Surface * originalSurface; // Load another SDL_Surface int w = Pove (2, boundary (log (original surface-> gt; w) / log (2)); // Two SDL_Surface * New Surface = Go to the nearest power of SDL_CreateRGBSurface (0, w, w, 24, 0xff000000, 0x00ff0000, 0x0000ff00, 0); SDL_ BlitSurface (original surface, 0, new surface, 0); // bleat on a purely RGB surface texture; Globe Texture (1, End Wit); GLBINNET (GL_TEXTURE_2D, WIT); GlTexImage2D (GL_TEXTURE_2D, 0, 3, w, w, 0, gl_rgb, gl_UNSIGNED_BYTE, new page- & gt; pixels);Something can happen as well.
Comments
Post a Comment