123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|729|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> C/C++/C#/Other -> OpenGL Texturing

Fri, 16 Mar 2007, 17:28
JL235
I have decided to get around to working on the new graphics back-end to the 'Game Creation Environment'. Rubygame is just too slow for drawing the amount of sprites I want to draw, so I'm trying to replace it with my own partial graphics library powered by OpenGL.

Two questions: First, what is the best way to load a texture in OpenGL? Currently I'm trying to load through an SDL layer, but when I transfer it across the colours are wrong (blue instead of red) and it's upside down (although I can rotate it).

This leads me on to my second question: How can I accurately rotate and scale with SDL? Rotating by 180 leaves a 1 pixel line across on side (can you flip?). I also want to allow the use of textures of any size. I planned to re-scale the image so it is 256x256, and simply make the polygon being used the size of the original image (and so scaling the image back to it's correct original size). However SDL is REALLY inaccurate when transforming making this impossible.

Any suggestions would be appreciated.
Fri, 23 Mar 2007, 16:32
HoboBen
Hi, Diablo.

I've not used Rubygame, but have you tried the NeHe OpenGl tutorials?

I used those to help me with OpenGL and C++, and never had your problems. Maybe they'll be of some use.

NeHe homepage

-=-=-
blog | work | code | more code
Fri, 23 Mar 2007, 16:47
JL235
My question isn't meant as specific about Ruby or Rubygames (which I'm not using anymore). More about SDL and OpenGL, and specifically about how to get an image loaded with SDL to become an OpenGL texture.

I have looked at those tutorials, but many use things specific to that language to load textures. For example the Java code uses a 'TextureLoader' (I believe that was the name) which comes with a Java OpenGL library.
Fri, 23 Mar 2007, 17:05
garand
For "non-blitz" issues i think it best to search for hakuna mattata elsewhere. :wisemonkey:



GameDev.net!
Sun, 25 Mar 2007, 14:57
JL235
Well, I figured out the problem. SDL's surfaces pixels go BGR not RGB, and so their pretty much backwards (like a bitmap file).

With a few OpenGL examples you can use 'GL_BGR' when loading the pixel data and setting it to the texture, but for some reason this is missing from both the Ruby version of OpenGL and several OpenGL documentations (so maybe this is a new addition).

However, in regards to my Game Creation Environment, I've decided in the short term to simply wrap SDL directly rather then use Rubygames (as I was also wrapping Rubygames myself, so it would have ended up being an SDL wrapper-wrapper). This and lowering the colour depth has double my frame rate!

But I have just realised how to reverse the SDL surface very easily (and quite quickly) in Ruby, by unpacking the surface, reversing the array, moving one digit from the beginning to the end, and packing it back up. Now if I can figure out an easy way to change the size, I can use OpenGL!

|edit| Also from early tests, drawing textured OpenGL polygons is twice the speed of blitting with SDL, so I'm definitely going to try to implement some form of OpenGL system. |edit|
Sun, 25 Mar 2007, 17:04
HoboBen
Cool

I'm glad you're making progress.