Sign in to follow this  
robolee

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

Recommended Posts

You can't do jack without the code so I'll post it right off the bat:

[url="http://pastebin.com/6C2RTMb2"]http://pastebin.com/6C2RTMb2[/url] -draw.h
[url="http://pastebin.com/6ysGygxp"]http://pastebin.com/6ysGygxp[/url] -draw.cpp (using texture rectangles)
[url="http://pastebin.com/R7Daf8n5"]http://pastebin.com/R7Daf8n5[/url] -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 [i]for me[/i], my friend [i]claims[/i] 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: [url="http://pastebin.com/ejkj2hvm"]http://pastebin.com/ejkj2hvm[/url] 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. Edited by robolee

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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". [i]IF[/i] 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 [i]neither method[/i] worked. This was just a new thing I tried more recently which is why it's in the main code instead of texture_2d.

[b]Anyway [/b]anyone got any advice on the second issue (rotation)? Edited by robolee

Share this post


Link to post
Share on other sites
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
[CODE]
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_LESS_EQUAL, f);
[/CODE]
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!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this