![]() |
SDL 2.0 Surface to OpenGL Texture | ![]() |
![]() |
SDL 2.0 Surface to OpenGL Texture | ![]() |
Chris Bush
Guest
![]() |
![]() |
On Tue, May 15, 2012 at 12:29 AM, Alex Barry wrote:
Try changing format GL_RGB to GL_RGBA in this line: glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24/*3*/, w, w, 0, GL_RGB, GL_UNSIGNED_BYTE, newSurface->pixels ); |
||||||||||||||||||
|
![]() |
SDL 2.0 Surface to OpenGL Texture | ![]() |
Patrick Baggett
Guest
![]() |
![]() |
On Mon, May 14, 2012 at 11:29 PM, Alex Barry wrote:
Second, you didn't specify any mipmaps but the texture filter mode defaults to GL_NEAREST_MIPMAP_LINEAR. When you have specified a texture but no mipmaps and use a texturing filtering mode that uses mipmaps, OpenGL calls the texture "incomplete" and treats it as if you had no texture at all. Try adding this after you bind the texture to use bilinear filtering with no mipmaps: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); Unlike in D3D, textures, not the texture units, carry the parameters like filtering/repeat mode, so you'll need to set this for every texture. If you want mipmaps and have OpenGL v1.4 or later, try: glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
Just a quick note: scissor tests aren't free. If you have viewport == scissor, then you're effectively doing a no-op but paying a price. The area in the scissor test should always be a proper subset in the viewport's area.
Let me know if that fixes the issue. Good luck. Patrick
|
||||||||||||||||||||||||||
|
![]() |
![]() |
Atis
![]() |
![]() |
Here's the code that I use with SDL2 to convert a surface into texture.
Note the lines that disable blending for source surface which seem to be necessary when the original image surface has an alpha channel.
|
||||||||||||
|
![]() |
SDL 2.0 Surface to OpenGL Texture | ![]() |
MrOzBarry
![]() |
![]() |
Still no luck.I added the glEnable for the texture (As Patrick suggested), which I thought was possibly the biggest issue - didn't fix the immediate problem, but I'm sure it was contributing.
Here is the new code for binding my texture:
Also, here is my updated opengl setup code:
I decided to open add a new window to test my surface just for a sanity check - everything looks perfect in the surface, so the issue is definitely in converting the surface to an OpenGL texture. I wrote my own exception stuff, and I'm getting an opengl error on my glTexSubImage2D call, and glGetError() gives me `GL_INVALID_VALUE` I've tried going over all my stuff, tried a few different values (see my SDL_PixelFormatEnumToMasks call), and I either get a white or a blue-green box, but not my texture :( Sorry to keep bothering you gents with this, again, I can move it to gamedev if it's more appropriate there. Also, thanks Atis for that code, I feel like it was a step or two in the right direction. And to Patrick and Chris for advice and ideas. -Alex On Tue, May 15, 2012 at 10:17 AM, Atis wrote:
|
||||||||||||||||
|
![]() |
SDL 2.0 Surface to OpenGL Texture | ![]() |
Jonny D
![]() |
![]() |
Is any of this necessarily specific to SDL2? The gpwiki page on loading an SDL_Surface to an OpenGL texture works for SDL1.2: http://content.gpwiki.org/index.php/SDL:Tutorials:Using_SDL_with_OpenGL
Jonny D |
||||||||||
|
![]() |
SDL 2.0 Surface to OpenGL Texture | ![]() |
Patrick Baggett
Guest
![]() |
![]() |
On Tue, May 15, 2012 at 10:21 AM, Alex Barry wrote:
The glTexImage2D( ....., NULL); glTexSubImage2D( .... ); pattern isn't required. You can do it all in one step in your case. Seeing as how you're going GL_INVALID_VALUE, that tells me your width and height are likely wrong. They need to be a power of 2*. *GL_ARB_texture_non_power_of_two relaxes this. http://www.opengl.org/registry/specs/ARB/texture_non_power_of_two.txt
|
||||||||||||||||||||||
|
![]() |
SDL 2.0 Surface to OpenGL Texture | ![]() |
MrOzBarry
![]() |
![]() |
That's actually the code I started with, and didn't have success. =/
On Tue, May 15, 2012 at 11:31 AM, Jonathan Dearborn wrote:
|
||||||||||||
|
![]() |
SDL 2.0 Surface to OpenGL Texture | ![]() |
Jonny D
![]() |
![]() |
Well, I adapted that for SDL_gpu (http://code.google.com/p/sdl-gpu/) and got it to work. Maybe you can look through the SDL_gpu source? Check out OpenGL/SDL_gpu_OpenGL.c, specifically Init(), CopyImageFromSurface(), and Blit(), though Blit() is a little obfuscated by features. I'm also assuming NPOT texture support.
Jonny D |
||||||||||
|
![]() |
SDL 2.0 Surface to OpenGL Texture | ![]() |
MrOzBarry
![]() |
![]() |
Thanks gents, I got this working, and it turns out most of my issue was that I wasn't using proper coordinates for aligning the texture on my gl quad vertices. Anyway, I fixed that up, and it's pretty awesome.
Anyone interested in the code can peek at it here: https://github.com/mrozbarry/bitfighter-experiments/blob/master/bitfighter1.0/sdlutil.cpp SDL::Surface is the class you'll want to prod at, and the openglBindTexture method would be the exacting place to look. Thanks for all the help gents, you were super. -Alex On Tue, May 15, 2012 at 12:04 PM, Jonathan Dearborn wrote:
|
||||||||||||
|