OpenGL Texture to SDL_Surface

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: OpenGL Texture to SDL_Surface

Post by dandymcgee »

N64vSNES wrote:
dandymcgee wrote: If it's loaded in as an OpenGL tex where do you expect to magically find all of that information to construct an SDL_Surface?
I have no idea what your even talking about here, what I meant to say was you would be getting rid of information that can be usefull such as the dimensions of the image you've loaded and its color dept.
I believe he was implying he never had access to an SDL_Surface in the first place. If he does then there shouldn't have ever been any problem storing it somewhere (other than the extra memory).
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: OpenGL Texture to SDL_Surface

Post by N64vSNES »

dandymcgee wrote:
N64vSNES wrote:
dandymcgee wrote: If it's loaded in as an OpenGL tex where do you expect to magically find all of that information to construct an SDL_Surface?
I have no idea what your even talking about here, what I meant to say was you would be getting rid of information that can be usefull such as the dimensions of the image you've loaded and its color dept.
I believe he was implying he never had access to an SDL_Surface in the first place. If he does then there shouldn't have ever been any problem storing it somewhere (other than the extra memory).
OK I think we're on the same page now :lol:
RandomDever
Chaos Rift Regular
Chaos Rift Regular
Posts: 198
Joined: Thu Mar 26, 2009 8:42 pm
Current Project: My Engine
Programming Language of Choice: C++

Re: OpenGL Texture to SDL_Surface

Post by RandomDever »

Alright first of all let me say the problem is solved I'm just going to include an SDL_Surface in my texture struct.
As for the mentioning of using SDL and OpenGL rendering at the same time, that was not my intention at all.
I just wanted to be able to modify the texture like applying a clip ( which is easier in SDL ).
And BTW I use SDL_image to load the textures so all I have to do is copy the SDL_Surface pointer.
However even though the problem which was listed in this topic is still valid and I would like to have a conversion rather than having an SDL_Surface in every texture there is a new problem.
OpenGL is returning 0 as the texture ID for a 128 by 128 .png and is refusing to draw it.
Does anyone have any idea why?
RandomDever
Chaos Rift Regular
Chaos Rift Regular
Posts: 198
Joined: Thu Mar 26, 2009 8:42 pm
Current Project: My Engine
Programming Language of Choice: C++

Re: OpenGL Texture to SDL_Surface

Post by RandomDever »

I still need someone to help me fix the texture ID problem because it's a HUGE speed bump.
qpHalcy0n
Respected Programmer
Respected Programmer
Posts: 387
Joined: Fri Dec 19, 2008 3:33 pm
Location: Dallas
Contact:

Re: OpenGL Texture to SDL_Surface

Post by qpHalcy0n »

You should contact me on that. I posted a solution for ya. OpenGL will facilitate for you all of the information you need to retrieve the texture, load it into an SDL_Surface or what have you.
It would be difficult to say why the load fails without code, there's a couple reasons it would.
User avatar
Zer0XoL
ES Beta Backer
ES Beta Backer
Posts: 54
Joined: Fri Apr 24, 2009 1:18 pm
Current Project: Zelda untitled multiplayer game
Favorite Gaming Platforms: PC, GBA, N64
Programming Language of Choice: C++, Lua
Location: Sweden
Contact:

Re: OpenGL Texture to SDL_Surface

Post by Zer0XoL »

i found a function here that works awesomely :)

in "krumm"s post:
http://www.gamedev.net/community/forums ... _id=184477

might be of interest :)
Image
Im Blue
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: OpenGL Texture to SDL_Surface

Post by Ginto8 »

Zer0XoL wrote:i found a function here that works awesomely :)

in "krumm"s post:
http://www.gamedev.net/community/forums ... _id=184477

might be of interest :)
that's the other way around :roll: :mrgreen:
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
User avatar
Zer0XoL
ES Beta Backer
ES Beta Backer
Posts: 54
Joined: Fri Apr 24, 2009 1:18 pm
Current Project: Zelda untitled multiplayer game
Favorite Gaming Platforms: PC, GBA, N64
Programming Language of Choice: C++, Lua
Location: Sweden
Contact:

Re: OpenGL Texture to SDL_Surface

Post by Zer0XoL »

Ginto8 wrote:
Zer0XoL wrote:i found a function here that works awesomely :)

in "krumm"s post:
http://www.gamedev.net/community/forums ... _id=184477

might be of interest :)
that's the other way around :roll: :mrgreen:
oh :P, well i hope someone of interest sees it :)
Image
Im Blue
RandomDever
Chaos Rift Regular
Chaos Rift Regular
Posts: 198
Joined: Thu Mar 26, 2009 8:42 pm
Current Project: My Engine
Programming Language of Choice: C++

Re: OpenGL Texture to SDL_Surface

Post by RandomDever »

Here's my draw function:

Code: Select all

   glEnable( GL_TEXTURE_2D );
	glEnable( GL_BLEND );
	glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
	glTranslatef( x + ( w / 2 ), y + ( h / 2 ), 0 );

	glColor4f( 1, 1, 1, alpha );

	glScalef( scale, scale, scale );
	glRotatef( rotation, 0, 0, 1.0 );

	glBindTexture( GL_TEXTURE_2D, id );

	glBegin( GL_QUADS );

	glTexCoord2i( 0, 0 );
	glVertex3f( -w / 2, -h / 2, 0 );

	glTexCoord2i( 1, 0 );
	glVertex3f( w / 2, -h / 2, 0 );

	glTexCoord2i( 1, 1 );
	glVertex3f( w / 2, h / 2, 0 );

	glTexCoord2i( 0, 1 );
	glVertex3f( -w / 2, h / 2, 0 );

	glEnd();
	glDisable( GL_TEXTURE_2D );
	glDisable( GL_BLEND );
The texture will not draw on the quad.
qpHalcy0n
Respected Programmer
Respected Programmer
Posts: 387
Joined: Fri Dec 19, 2008 3:33 pm
Location: Dallas
Contact:

Re: OpenGL Texture to SDL_Surface

Post by qpHalcy0n »

If indeed your handle is zero, then you have not generated a texture handle or the img load (glTexImagexxxx) was passed an invalid parameter. This will result in a failure to apply the texture.

It's also possible that your blend mode does not agree with your pixel format. You need to have a valid format with some form of packed alpha in that.
Post Reply