Simple textures with GLUT? - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Simple textures with GLUT? (/thread-3374.html)
Simple textures with GLUT? - Canter - Apr 2, 2007 09:11 PM
I have this code to make a simple box. This box acts as more or less a sprite on the screen. This is a really n00bish question, but how do I get a texture to display on this object so it has an appearance? How do I get this texture to have transparency, like a GIF? I've only ever worked on consoles like the GBA before where there was a color that was transparent, this is completely different deal, heh.
Simple textures with GLUT? - StealthyCoin - Apr 2, 2007 11:00 PM
Steal someone's texture code. Probably OSC's. I can't find it, sorry, but I stole his.
Simple textures with GLUT? - OneSadCookie - Apr 3, 2007 12:00 AM
It's unfortunately not a very simple question. The transparency thing is easy; use a texture with an alpha channel (eg. a PNG file), and do
before you draw. Remember to turn blending off when you don't need it
For the texture-loading thing, you have a bunch of options. Easiest is probably to grab the code from http://onesadcookie.com/trac/browser/QTValuePak , but the warning is there for a reason. Using ImageIO/CoreGraphics is also relatively simple (search the boards and you'll find examples). If you need cross-platform, you need libpng or libjpeg. Source for something that uses both is here: http://onesadcookie.com/trac/browser/SimpleImage
Simple textures with GLUT? - PowerMacX - Apr 3, 2007 06:07 AM
Also, if you are going to use partial transparency, you'll need to render your quads back-to-front for them to show correctly.
Simple textures with GLUT? - DesertPenguin - Apr 3, 2007 06:19 AM
Here is the texture mapping tutorial from NeHe
Basically, you supply texture coordinates (u,v) for each vertex. The hardware then looks up the color at that location from the active texture unit in order to color the vertex.
You must also load an image and store it in a texture unit with:
and activate texture mapping with:
Hope that helps...
Simple textures with GLUT? - Canter - Apr 3, 2007 09:18 AM
Thanks to all who have helped so far!
However, this code, as mentioned from the "NeHe" tutorial, appears to not work...
Well, that returned 3 errors and 2 warnings, and provided (obviously) no function:
errors Wrote:error: parse error before '*' token
About the "undeclared" stuff, it wasn't declared in the example, so I wasn't sure wether to just make an int or whatever at the top.
I'm not sure what to do, like I said, I've never dealt with this before.
Simple textures with GLUT? - OneSadCookie - Apr 3, 2007 12:33 PM
The NeHe texture loading code is Windows-specific and ancient; it won't work on a Mac. Follow my links.
Simple textures with GLUT? - Canter - Apr 3, 2007 01:05 PM
Sorry, it's probably great stuff, but it's not really context-sensitive, I mean, what do I do with it? I'm sorry, it's probably great code, I just have no idea what I'm doing...
Simple textures with GLUT? - DesertPenguin - Apr 3, 2007 05:35 PM
One Sad Cookie is right - the NeHe tutorials are both ancient and window specific.
I posted them solely for the discussion regarding OpenGL texture loading.
Your problem stems from the need to load a texture from some kind of graphic file - like png, bmp,tiff,jpg. OpenGL does not provide a facility for this - it expects the raw image pixel data.
So basically you need some way to load a file and get the raw image data. Once you have that, just call something like:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
I personally use both SDL and SDL_image to read a png.
Hope that helps.
Simple textures with GLUT? - bronxbomber92 - Apr 3, 2007 05:52 PM
The links that OneSadCookie posted are the loaders that extract the raw pixel data for OpenGL to use, once you have that you can do what DesertPenguin said.
Simple textures with GLUT? - arekkusu - Apr 3, 2007 07:45 PM
The question of "how do I get a texture to display on this object" is different from "how do I load an image from disk to use as a texture." The first question is all about OpenGL. The second question is about your file system and your image libraries.
Both of these have been answered many times on this forum before. But to succinctly answer the first question, separate from the second:
Make sense? Not that much to it.
Simple textures with GLUT? - Canter - Apr 4, 2007 08:14 AM
Yeah, arekkusu, that's great, it worked for me. Now I need to get it to load the images, I'll try to work with OneSadCookie's code now that I know how it works.
EDIT: I still can't figure it out... >_<
Is there some sort of a tutorial?