Passing an image over to OpenGL?

BlitzMax Forums/OpenGL Module/Passing an image over to OpenGL?

IKG(Posted 2007) [#1]
I've been wanting to work with OpenGL for awhile now. I'm using BlitzMax just so it'll be easier to play sounds, detect input, and load images. By the way, this is all for a 2D game.

How would I load an image and pass it to OGL? Very basic, I know. I just never understood other "library" tutorials about loading an image and passing it over to OpenGL.


bradford6(Posted 2007) [#2]
use Max2D with the GL Driver. no need for direct 'raw' GL calls.


IKG(Posted 2007) [#3]
Well like I said, I'm doing this because I'm interested in OpenGL. If it wasn't for the sound, input, and image loading commands, I would just be doing this in something else like SDL.

I know there's other easy ways to do it obviously, but that's not what I'm looking for.


Dreamora(Posted 2007) [#4]
You could check out the GL module in brl modfolder especially the function that creates a GL texture from a pixmap.


ImaginaryHuman(Posted 2007) [#5]
If you really are interested in getting to know how to use OpenGL, I recommend you go online and search on google for the `openGL red book` and read all of it. There are various sections, reading the whole thing is very beneficial for learning to use OpenGL, starting from the beginning, as each builds upon previous knowledge. It will tell you the basics of what you need to do to achieve your aims and then you will understand how the various parts of the system work together. I read the entire thing, it's well worth it.

You can also search for the `opengl blue book` which basically is a list of all the commands, their syntax and descriptions of what they do.

You basically need to start by setting up the display, then you load in your pixmap with LoadPixmap, then you need to set up all the parameters that affect transfers to OpenGL such as glTexParameter and so on. You have to create a texture object, I think it's glGenTextures(), you then need to `bind` the object you created to the `GL_Texture_2D` object and then you then need to use glTexImage2D to actually upload the image, passing it the pointer (address) of the topleft corner of the pixmap. You may also then want to set a couple of parameters regarding smoothing/filtering. Then you have to go about defining some vertices, setting the vertex colors, defining the texture coordinates etc.

See my OpenGL blobby objects demo - it shows one way to read in and upload textures and then drawing them as images.

http://www.blitzbasic.com/Community/posts.php?topic=46378#516605

Note in the sourcecode there, that bglCreateContext() no longer exists, just use GLGraphics().


IKG(Posted 2007) [#6]
Thanks a lot AngelDaniel. That's exactly what I was looking for. I'll take a shot at it once the old wiki is available again.

Actually couldn't I use regular Max2D and switch to OpenGL to do pixel shaders?


Dreamora(Posted 2007) [#7]
No
Max2D uses a specific setup which you would need to "break" for your shaders. (you still could use it but it would be more than "setgraphicsdriver glmax2d()" to make it work)


IKG(Posted 2007) [#8]
Well I wanted to make a 2D game and fool around with shaders. A game called Facewound inspired me (http://www.facewound.com).

I didn't really understand your answer though. There's no way of programming in regular Max and then switching over to apply OGL shaders?


Dreamora(Posted 2007) [#9]
You could test it.
But normally no, at least unless you are willing to modify some code of the modules and recompile them (and thus apply that again with every new version), because Max2D initializes the GL context with flags that won't allow you much more than it actually does.