![]() |
|
OpenGL Image Textures - Printable Version +- iDevGames Forums (http://www.idevgames.com/forums) +-- Forum: Development Zone (/forum-3.html) +--- Forum: Graphics & Audio Programming (/forum-9.html) +--- Thread: OpenGL Image Textures (/thread-1114.html) |
OpenGL Image Textures - mikey - Jun 19, 2009 11:41 AM I am writing an OpenGL game in C, and I feel it would be much better if i could use textures. I have tried to muddle together some libpng stuff, but it's all too complicated. I can see how to actually write tex coordinates on a quad, but I don't see how to load the image. I'd be happy with any format bar JPEG or GIF, for obvious reasons. Can someone help? Thanks OpenGL Image Textures - SethWillits - Jun 19, 2009 02:11 PM http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=06 OpenGL Image Textures - mikey - Jun 20, 2009 03:12 AM Yes, I've seen that before, but that makes use of <glaux.h>, which is windows only. It's not really the actual textures I'm stuck with, it's getting the image into an OpenGL texture. OpenGL Image Textures - SethWillits - Jun 20, 2009 10:37 AM Quote:Yes, I've seen that before, but that makes use of <glaux.h>, which is windows only. There's Mac OS X code at the bottom of every NeHe tutorial. Also, if you search these forums, Apple examples, and the net in general, you'll find lots of texture loading code. It comes up often. OpenGL Image Textures - mikey - Jun 20, 2009 10:43 AM Yes, I have looked at the OSX code for that tutorial, but I don't understand it, and when I try and copy it, I get loads of errors. As for Apple examples... Well, the amount of code that's not ObjC, and not Legacy is small. Still, I'll look again... OpenGL Image Textures - mikey - Jun 20, 2009 11:04 AM ... Nope. Can't find anything that's not C++ or ObjC or Windows or Linux. Can you help?
OpenGL Image Textures - ThemsAllTook - Jun 20, 2009 11:23 AM Give this a try: http://developer.apple.com/graphicsimaging/workingwithimageio.html If ImageIO doesn't work out, try this: http://www.google.com/search?client=safari&rls=en-us&q=site:idevgames.com+texture+loading&ie=UTF-8&oe=UTF-8 OpenGL Image Textures - mikey - Jun 20, 2009 12:09 PM Sorry if I seem stupid, but I don't get any of these. The ObjC just confuses things. And I don't even know what CGImage is. I find the Apple code is all too... politically correct, so much so It becomes unreadable. OpenGL Image Textures - ThemsAllTook - Jun 20, 2009 12:42 PM You can't expect to understand something this involved when you spend less than an hour reading about it. If there's a part of the API that doesn't make sense to you (for example, if you don't know what a CGImage is), look it up in Apple documentation and keep reading until you do understand it. If you don't have the patience or dedication to do that, programming may not be an appropriate hobby for you. OpenGL Image Textures - unknown - Jun 20, 2009 01:12 PM I might put something together.
OpenGL Image Textures - unknown - Jun 20, 2009 02:14 PM I've made a tool for putting images into C source code for OpenGL. To compile the tool use: gcc OpenGLTextureMaker.m -framework Cocoa -o OpenGLTextureMaker Code: #import <Cocoa/Cocoa.h>run it like this: ./OpenGLTextureMaker example_image.png > output.txt fix the output up and then paste it into Code: #include <OpenGL/gl.h>and compile that using: gcc -framework GLUT -framework OpenGL textureexample.c -o textureexample to see it working. Edit: Remember to use textures that have dimensions that are powers of two! OpenGL Image Textures - SethWillits - Jun 20, 2009 02:27 PM mikey Wrote:Yes, I have looked at the OSX code for that tutorial, but I don't understand it Which is normally where you ask a question about the code, not ask for different code. What makes you think you'll understand different code anymore than the working code you've already seen? Quote:and when I try and copy it, I get loads of errors. Well, that's your fault, not the code's. ![]() And again, this would be something you'd ask a question about. You're clearly missing something important and relevant that you'd likely miss with any other code. Quote:As for Apple examples... Well, the amount of code that's not ObjC, and not Legacy is small. Likability/usefulness of specific APIs aside, there's no reason to avoid Obj-C just because it's "not C". You can easily use the two together, and having platform-specific code in a cross platform app is common. The language shouldn't be an issue. And there's always third party code like SDL_image that you could use. OpenGL Image Textures - mikey - Jun 21, 2009 01:51 AM Thankyou very much unknown! ![]() ![]() ![]() ![]() ![]() FreakSoftware: Yes, you're probably right. Thanks anyway though. ![]() Quote:You can't expect to understand something this involved when you spend less than an hour reading about it. If there's a part of the API that doesn't make sense to you (for example, if you don't know what a CGImage is), look it up in Apple documentation and keep reading until you do understand it. If you don't have the patience or dedication to do that, programming may not be an appropriate hobby for you. You're right. I'm rushing. Thanks. OpenGL Image Textures - johncmurphy - Jun 21, 2009 11:29 AM [INDENT]I've been researching this topic for a tutorial that I am working on. I am surprised at how little there is currently available on this topic. Here are my findings:[/INDENT] [INDENT] In the Apple sample code there is the Texture2D class that will load an image as a texture, resize it as needed, invert it, and display it on a quad. The problem is that it freely mixes OpenGL with Objective-C, which makes it very fragile and problematic for beginners. Then there is the image loading code from the GLSprite sample code, which is easier to understand, but also rather fragile since it requires that the source image be in the right format and a power of two size, otherwise nothing will show up onscreen.[/INDENT] In the end, I came up with this hybrid code: Code: glGenTextures(1, &textureID); which loads an image that can then be draw using something like this: Code: glBindTexture(GL_TEXTURE_2D, textureID); OpenGL Image Textures - Frogblast - Jun 21, 2009 01:29 PM Why are you enabling blending? Also, please hoist the line that sets GL_TEXTURE_MIN_FILTER to occur before the call to glTexImage2D. It is correct either way, but setting the min filter before creating texture level 0 may allow GL to operate more efficiently. |