Non-square, non-POT, hardware-accelerated surfaces...

NekoYasha
Unregistered
 
Post: #1
I would really like to know if this can be done. For a game I want to begin working on, I need to use non-square, non-POT surfaces in many places. I also don't want to use SDL blit functions, because it needs to be as fast as possible when using alpha transparency, and I know from experience that blitting in SDL is horribly slow for just about any blitting, let alone blitting PNG images with alpha channels.

I am currently playing around with SDL-OpenGL, using quads for 2D surfaces. I have found it to be exactly what I'm looking for, except for one minor issue: It renders fully white unless the texture has dimensions that are powers of two. I have tried mipmaps, but they look really crappy. Besides, I would really prefer to display images on the screen with pixel-perfect accuracy whenever possible.

Is this at all possible? Or should I forget about it and move on to some other API that can do what I need to do? I'd rather not pay for Torque 2D, but I can if I need to.

Thank you,
Albert
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #2
Just make your image as usual, scale it to the nearest powers of 2 (don't worry about distortions), then map it to a quad. Assuming you do your texture coordinates correctly, it will scale your texture, un-distorting it.
Quote this message in a reply
NekoYasha
Unregistered
 
Post: #3
I suppose I could do that, but the problem is that the way my game is now, it automatically takes the image dimensions and makes a quad of the proper size for it. I'd rather not lose that functionality, but I guess I could give your idea a shot and see how I can make it work.

If anyone has any other ideas, please don't hesitate to help.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #4
You can use rectangle textures if you don't care about anything lower than Radeon/GF2MX.

TEXTURE_RECTANGLE_EXT

The coordinates are also in pixels instead of being clamped to [0.0, 1.0], which can make life easier for 2D stuff.

To use them, simply supply GL_TEXTURE_RECTANGLE_EXT, where you would use GL_TEXTURE_2D.
Quote this message in a reply
Member
Posts: 184
Joined: 2004.07
Post: #5
Alternatively, you could pad out the rest of the power of two with completely transparent pixels.
Quote this message in a reply
Member
Posts: 257
Joined: 2004.06
Post: #6
Also, you could try glpng.

The brains and fingers behind Malarkey Software (plus caretaker of the world's two brattiest felines).
Quote this message in a reply
NekoYasha
Unregistered
 
Post: #7
Wow...considering how sparse posts seem to be in this section of the forums, I'm surprised at how many responses I got.

Skorche: That looks like it may be just what I need. I'll try it out and see how it goes.

phydeaux: I thought about doing that, but decided that unless I was really desperate, it would not be practical. It's really just a waste of memory. It would work, though.

Malarkey: I have never gotten that thing to compile. Ever. I think it hates me or something.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #8
EXT_texture_rectangle is almost certainly the right way to go. Be aware that it's not supported on Rage 128s, and that it comes with a few caveats as compared with normal power of two texturing.
Quote this message in a reply
NekoYasha
Unregistered
 
Post: #9
Well, it's working perfectly. Thank you so much, everyone.

One last question, though: will this extension work on OS's other than Mac OS X (at least Windows)? I did a Google search, but only found information related to OS X development. I'd test it myself, but I don't have Windows available to me right now.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #10
it's called various things in various places. NV_texture_rectangle, EXT_texture_rectangle and ARB_texture_rectangle are all the same thing, though, just different names for the same thing. You'll find all recent drivers for ATI and NVidia cards on Windows and Linux support the ARB flavor, and the EXT flavor is available on Macs since about 10.1.
Quote this message in a reply
NekoYasha
Unregistered
 
Post: #11
So I guess a couple of #ifdefs will solve any problems, then? Cool, I guess that's all I need to know.

Thanks for all of the help, everyone.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #12
you don't need any #ifdefs, even.

just check for the presence of one of those three extensions, and treat it as if a particular one were available (GL_TEXTURE_RECTANGLE_NV == GL_TEXTURE_RECTANGLE_EXT == GL_TEXTURE_RECTANGLE_ARB == 0x84F5).
Quote this message in a reply
Member
Posts: 257
Joined: 2004.06
Post: #13
NekoYasha Wrote:Malarkey: I have never gotten that thing to compile. Ever. I think it hates me or something.

Really? I could probably send you my Xcode project of it if you're interested (after I make sure it still compiles).

The brains and fingers behind Malarkey Software (plus caretaker of the world's two brattiest felines).
Quote this message in a reply
NekoYasha
Unregistered
 
Post: #14
OneSadCookie: Oh, okay. I get it now. Thanks.

Malarkey: I think SDL_image and GL_TEXTURE_RECTANGLE_EXT should work just fine for me, but if possible, I'd still like to see that Xcode project. You can send it to NinjaApprentice@gmail.com.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Want good color interpolation for my square Najdorf 2 4,011 Nov 22, 2009 10:11 PM
Last Post: Najdorf
  Trying to make a square... there's a triangle! TimMcD 4 3,865 Jun 2, 2009 03:41 PM
Last Post: AnotherJake
  texture no square surface kendric 7 4,539 Mar 20, 2009 05:26 PM
Last Post: kendric
  Create surfaces with custom data manu1001 0 1,906 Feb 6, 2008 09:48 AM
Last Post: manu1001
  GLSL hardware support ia3n_g 4 4,438 Oct 6, 2006 08:28 PM
Last Post: ia3n_g