![]() |
|
Displaying image with OpenGL and DevIL in C? - Printable Version +- iDevGames Forums (http://www.idevgames.com/forums) +-- Forum: Development Zone (/forum-3.html) +--- Forum: Graphics & Audio Programming (/forum-9.html) +--- Thread: Displaying image with OpenGL and DevIL in C? (/thread-3540.html) |
Displaying image with OpenGL and DevIL in C? - leRiCl - Jan 21, 2007 09:49 PM how to display image with OpenGL and DevIL? Or is this not possible, and I must use libs like libPNG instead? Code: ilutGLLoadImage("/Users/eric/GLExperiment/Images/fighter.png");This code doesn't do anything. Not surprisingly.. and then I tried using textures... Code: ilutGLLoadImage("/Users/eric/GLExperiment/Images/fighter.png");This code manages to turn every shape's colour in the screen to the most predominant colour in the image. I was trying to do it with textures. Displaying image with OpenGL and DevIL in C? - akb825 - Jan 21, 2007 09:58 PM The texture coordinates should go from 0 to 1. So where you have glTexCoord2f(X1, Y1), you should have glTexCoord2f(0, 0). Also, in place of glVertex2f(X1 + Width, Y1 + Height), you should have glVertex2f(1, 1). I'm sure you can figure out the rest.
Displaying image with OpenGL and DevIL in C? - OneSadCookie - Jan 22, 2007 01:17 AM and I'm sure ilGetData is a function, not a global variable! Displaying image with OpenGL and DevIL in C? - leRiCl - Jan 22, 2007 03:51 AM akb825 Wrote:The texture coordinates should go from 0 to 1. So where you have glTexCoord2f(X1, Y1), you should have glTexCoord2f(0, 0). Also, in place of glVertex2f(X1 + Width, Y1 + Height), you should have glVertex2f(1, 1). I'm sure you can figure out the rest. I did that thing OneSadCookie told me in his tutorial. -> make the coordinate system measure interms of pixels instead of the default system. I still use the coordinates you told me OneSadCookie Wrote:and I'm sure ilGetData is a function, not a global variable! Its a function, I can use it like this, right? It gets the memory address of the image I loaded, and returns it as a pointer. Displaying image with OpenGL and DevIL in C? - OneSadCookie - Jan 22, 2007 03:57 AM Function calls in C always have parentheses. Displaying image with OpenGL and DevIL in C? - leRiCl - Jan 22, 2007 04:24 AM OneSadCookie Wrote:Function calls in C always have parentheses. >.> Why didn't it give me an error? Displaying image with OpenGL and DevIL in C? - OneSadCookie - Jan 22, 2007 04:29 AM In C, you can pass any kind of pointer as a void*. You were passing a function pointer. Displaying image with OpenGL and DevIL in C? - leRiCl - Jan 22, 2007 04:31 AM I put the parenthesis in, now all the rectangles and lines on my app flash green blue and red, make my head dizzy.. >< But I still don't see any image! Note that I am able to get data about the image, eg. its width and height, so I am sure I have it loaded into the app. Code: 'see other posts. deleted for space.Displaying image with OpenGL and DevIL in C? - akb825 - Jan 22, 2007 11:38 AM You still haven't changed the texture coordinates. Having the coordinate system match up pixel by pixel works with the vertex coordinates, but not the texture coordinates. Like I said earlier, they go from 0 to 1: always. (unless you are using GL_TEXTURE_RECTANGLE_EXT/ARB instead of GL_TEXTURE_2D, but that's the only exception) Also, you can't just say "TexID = 2". You have to call glGenTextures first. Displaying image with OpenGL and DevIL in C? - OneSadCookie - Jan 22, 2007 01:45 PM akb825 Wrote:Also, you can't just say "TexID = 2". You have to call glGenTextures first. Unfortunately, you're wrong about that. You *can* choose your own texture IDs, and OpenGL just has to deal. This is something that they will fix for OpenGL LM / OpenGL 3.0. You're right, though, that you *should* call GenTextures. leRiCi, isn't there a DevIL function that does the TexImage2D for you? Displaying image with OpenGL and DevIL in C? - leRiCl - Jan 22, 2007 03:43 PM There is, but the example containing the command won't compile. Anyways... I realised I posted the wrong version of the code I had. Here, I called GenTextures and didn't declare my TexID and changed the texture coordinates and used the GL command for DevIL. Now it doesn't do anything at all. >< Code: // GL texture IDDisplaying image with OpenGL and DevIL in C? - akb825 - Jan 22, 2007 04:29 PM What's the value of X1 and Y1? Are you trying to give the value of the window's x and y? If so, don't. Assuming you correctly set up the orthographic matrix (for example, with glOrtho(0, width, 0, height, 1, -1)) and viewport (for example, glViewport(0, 0, width, height)), the viewable coordinates should be 0-width for the x and 0-height for the y. Displaying image with OpenGL and DevIL in C? - leRiCl - Jan 22, 2007 04:36 PM I want to put my head in the toilet and flush it away.... I called this function before glClear.... *sigh* It probably had always been working, and I was just wasting my time. Sorry guys. but thanks. Displaying image with OpenGL and DevIL in C? - djork - Jan 23, 2007 01:25 PM leRiCl Wrote:I want to put my head in the toilet and flush it away.... I called this function before glClear.... *sigh* It probably had always been working, and I was just wasting my time. Sorry guys. but thanks. No sweat. I did the same thing yesterday. I was pulling my hair out trying to figure out why my screen was blank. |