Click here to Skip to main content
15,875,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm using OpenGL and GLUT together with the library SOIL and trying to program a simple 2D game,
I succeeded uploading pictures onto the window but I didn't understand something. Usually at sprites in programs you got pictures like http://www.luxinia.de/uploads/Tutorials/explosprite.png
It's a couple of frames in ONE picture so it saves memory and is more useful and comfortable. I don't know hot to do that, is there any built-in functions in SOIL or any way to do that in openGL or GLUT ? You know, INSTEAD of saving it to 16 different pics (which I did, untill I get a solution)
Posted

1 solution

You would do exactly the same thing as always just draw part of the bitmap. That said most of us just get frustrated with GLUT and give up and go direct onto the Win32 OpenGL API which is much easier. If you reach that frustration point a good start point is here

http://bobobobo.wordpress.com/2008/02/11/opengl-in-a-proper-windows-app-no-glut/[^]
 
Share this answer
 
v2
Comments
Member 10823297 16-May-14 10:57am    
Why frustrated ? It seems really easy this far. I just looked over a couple of Win32 OpenGL API codes and I don't know what you're talking about (when saying they're much easier). Anyway, it's not the same as BMP as I load BMP onto an two-dimen array of pixels and use GLDrawPixels but in PNG i use GLuint containing texture. I don't know how to access the pixels in the textures. Any idea?
leon de boer 16-May-14 23:47pm    
It's easy but you can't work it out :-) I will tell you what I know which is limited because this rubbish annoyed the hell out of me.

You take your GLuint and you end up creating your 2D image by using glTexImg2D which carries two parameters which are glTexCoord2d and are numbers ranging from 0 to 1, so 0.5 is half way along the image etc. This for me created the first set of problems in that you can't nominate a pixel width so you need to pad the space between your images to allow for rounding errors especially if the two textures in side by side are very very different. The official line is "This has the advantage of being size-independent"

So when you are in OpenGL forget about pixels and widths, heights everything is a number between 0 and 1.

I have seen some sidestep the issue by loading JPG,BMP, PNG etc to a standard Win32 bitmap and then create a DIB section off it and pass that to the create texture in OpenGL like you are doing. In other words they do all the bitmap slice and dicing down on the Win32 API and simply pass the result out to OpenGL.

So get thru that and lets see which of the problems you run into next.
Member 10823297 17-May-14 15:15pm    
I have SOIL though and I've created the function DrawImage with X, Y, Height, Width, angle and all so it's kind of helpful

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900