Sprite transparency in OpenGL?

Luminary
Posts: 5,143
Joined: 2002.04
Post: #16
To be clear: you have no need to call glTexSubImage2D for a sprite game. TexSubImage2D *is* slow, because it involves transferring data from the CPU to the GPU.

Create your textures once, bind and draw as necessary each frame.

And, GeForce 2MX?! Why are you using a ten year old graphics card?
Quote this message in a reply
Member
Posts: 96
Joined: 2011.07
Post: #17
yep. doesn't sound very feasible. still, as a thought experiment it sounds intriguing. What about VBOs? Isn't that kind of like a "hardware sprite"?

[Normally, I have a new mesh/quad for every frame, i.e., vertex pointer, but I keep my textures bound once (usually)].

respect,
pk

iFrog is coming.
Quote this message in a reply
Member
Posts: 260
Joined: 2005.05
Post: #18
(Dec 20, 2011 11:21 AM)OneSadCookie Wrote:  To be clear: you have no need to call glTexSubImage2D for a sprite game. TexSubImage2D *is* slow, because it involves transferring data from the CPU to the GPU.

Now wait a minute. I think you just confused glTexSubImage2D with glReadPixels? The glTexSubImage2D call is fast and optimized and should not transfer data to the CPU. Rather, it is the backup call if you can't use FBOs (if you find FBOs to hard to use or you use an ancient system that doesn't support them.) But glReadPixels (combined with a glTexImage) is exactly what you describe, drawing to a texture the slow way. over the CPU.

But for the main question I agree, you are not likely to save time by doing more work, in this case render all sprites to a texture and then render that. And transparency for 2D sprites is easy. Get those done and start thinking about the harder parts, like a good collision detection/collision handling system.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #19
No, he said transferring from the CPU to the GPU. Refreshing a texture every frame is most certainly slower than reusing the same one over.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Member
Posts: 96
Joined: 2011.07
Post: #20
I just started thinking about "mesh sprites" that are 2D meshes with minimal or no transparency. Designing them would be different than making animated quads (where you usually have quite a lot of transparency). The bound bitmap would be more like a palette/texture, like with 3D objects.

respect,
pk

iFrog is coming.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #21
You could certainly do that, but why bother?
Quote this message in a reply
Member
Posts: 260
Joined: 2005.05
Post: #22
(Jan 7, 2012 07:26 AM)Skorche Wrote:  No, he said transferring from the CPU to the GPU. Refreshing a texture every frame is most certainly slower than reusing the same one over.
Same thing. If you use glTexSubImage2D, you don't transfer in either direction, it is all on the GPU.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #23
TexSubImage2D is CPU->GPU.
CopyTexSubImage2D is GPU->GPU.
Quote this message in a reply
Member
Posts: 96
Joined: 2011.07
Post: #24
(Jan 7, 2012 11:03 AM)OneSadCookie Wrote:  You could certainly do that, but why bother?

I'm thinking about cutting down the app size by avoiding a lot of texture sprites and somewhat a different look.

respect,
pk

iFrog is coming.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #25
I don't think it would save any app size or allow any different look...
Quote this message in a reply
Member
Posts: 96
Joined: 2011.07
Post: #26
(Feb 16, 2012 03:35 PM)OneSadCookie Wrote:  I don't think it would save any app size or allow any different look...

We can settle the score over a game of chess...

respect,
pk

iFrog is coming.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #27
(Feb 16, 2012 03:35 PM)OneSadCookie Wrote:  I don't think it would save any app size or allow any different look...

Sure it would. With sprite animation you have to store a lot of discrete frames. With meshes you could do a lot of effects that are traditionally done with 3D models. Think like Another World or Flashback for example.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Sprite game with OpenGL/GLKit InvisibleMoustache 6 8,424 Oct 10, 2012 09:20 AM
Last Post: OneSadCookie
  OpenGL ES 2.0, 2D Alpha Transparency Artifacts Macmenace 3 7,845 Mar 28, 2010 11:18 PM
Last Post: AnotherJake
  libpng transparency problem wyrmmage 3 5,286 Mar 1, 2007 05:53 PM
Last Post: OneSadCookie
  OpenGL Sprite Structure Stalin55 2 4,289 Aug 18, 2006 03:40 PM
Last Post: AnotherJake
  SDL + OpenGL Sprite Loading Problem Greywhind 3 4,999 Jun 29, 2006 04:44 PM
Last Post: OneSadCookie