rendering as white rectangle + image rotation issue + any advice to improve the code

Started by
2 comments, last by Koehler 11 years, 9 months ago
You can't do jack without the code so I'll post it right off the bat:

http://pastebin.com/6C2RTMb2 -draw.h
http://pastebin.com/6ysGygxp -draw.cpp (using texture rectangles)
http://pastebin.com/R7Daf8n5 -draw.cpp (replacement functions for using texture_2d instead of texture rectangles)

So, first of all I'll just say that it's all fully working 2d sprite rendering code... That is to say fully working for me, my friend claims that no matter what I change my draws just render as white rectangles, despite the fact that it's fully working on my own machine (nvidia 8800gt) and an old crappy laptop I own which only has intel integrated graphics. I just wanted to know if it should be working properly and it's just a driver error/problem on his half. Also other than that I would like general advice on how I could improve and also what I can do to make it as compatible as possible.

Secondly when doing smooth rotation using linear interpolation on the min and mag filters I get magenta fuzz around the sprite (magenta is set to 0 opacity on image load) and image zoom is linear as well. Nearest Neighbour zoom is good but the rotation is horrible. Is it possible to get smooth rotation without the magenta fuzz and to scale up using NN? I guess ideally what I want is AA for the edge of the sprite whilst using NN body rotation and zoom, which I hadn't thought of until I just came to write it down. Is that easily achievable?




some notes(/brain farts - ignorable):
Texture rectangles seem a lot easier to set up but support should be a lot less, especially for older hardware. The last thing I was going to try with Texture_2D is matching/square power of 2 w&h (32*32, 64*64 etc.), the last thing I did there was to make it power of 2 w&h but nearest increment for w&h separately (so it could be 32*64, 64*128 etc.) which I thought should be extremely compatible?
Here's my self written image loader if you wanted to view it: http://pastebin.com/ejkj2hvm at the moment it only loads and saves 24bit BMPs, honestly I don't need any more functionality than that and it was fun to learn. If I wanted to load more types I won't be trying that myself, BMPS are far enough in terms of enjoyment/difficulty to implement.
And just for my interest would porting this code to OGL ES be straightforward? This is just a secondary question I don't plan to any time soon but my friend thinks that it would be cool to port an app to the iPhone or iPad (though honestly I personally hate apple products) and besides it won't be happening for a while anyway even I decided I wanted to.
Advertisement
GL_TEXTURE_RECTANGLE_NV

This should not be necessary. I have no idea what it actually does, but I never use it for non-square textures. You can always call glGetError or glGetLastError or whatever it is, to find the issue.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

GL returns no errors using either GL_TEXTURE_2D or GL_TEXTURE_RECTANGLE_NV (just tested using both). - "So, first of all I'll just say that it's all fully working 2d sprite rendering code... That is to say fully working for me". IF there's an issue then it is an issue of compatibility I believe. Like I said I think it's a problem on his end (dodgey driver or copying wrong files or other user mistake), I just want to know if I'm not crazy and it should be working or if there's some genuine compatibility problem.

And of course texture rectangles aren't necessary, texture rectangles just make the texture generation a little simpler (you use 1:1 pixel coordinates instead of normalized coordinates), but aren't be compatible with old hardware. However this friends hardware is relatively new and neither method worked. This was just a new thing I tried more recently which is why it's in the main code instead of texture_2d.

Anyway anyone got any advice on the second issue (rotation)?
This code won't port to OpenGL ES. The matrix stack (glTranslate, glRotate, etc) doesn't exist in that standard. You are expected to keep track of them yourself and pass the values to shaders, where you transform the vertices yourself. It also does not support the glVertex line of functions ( You have to use vertex arrays or VBOs), and works without a fixed-function pipeline (meaning shaders are required).

It sounds like linear interpolation is yielding magenta "fuzz" because it's averaging magenta with zero alpha with whatever your sprite color is, (at 1.0 alpha most likely).
If you call

glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_LESS_EQUAL, f);

Where f is a floating-point value between 0 and 1 (you'd have to experiment to see what looks good), your fuzz might clear up. Note that this means any pixels with an alpha value below f will now not be drawn!

This topic is closed to new replies.

Advertisement