Jump to content
  • Advertisement
Sign in to follow this  
schragnasher

OpenGL DevIL, GLFW and confusion

This topic is 3607 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im trying to get a simple test run to work for a 2d game. Just a simple thing to get to know OGL more. Right now it uses immediate mode just to make things simple. Im trying to get images to work correctly. Iv been able to do it in some instances, but not others using DevIL. Using only DevIL code i was able to get it to work, but when i tried to load and display a background of 800x600 it displayed a horribly downgraded version, likely a stretch out image resized for under 256x256 for some reason i cant understand as my video card should be able to handle more. Anyhow, iv tried loading the image directly with a tutorial from the GPWiki...
Quote:
#include <GL/glfw.h> #include<IL/il.h> #include<IL/ilu.h> #include<IL/ilut.h> int main() { bool running = true; glfwInit(); ilInit(); iluInit(); ilutRenderer(ILUT_OPENGL); glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE,GL_TRUE); glfwOpenWindow( 800, 600, 0, 0, 0, 0, 0, 0, GLFW_WINDOW ); glfwSetWindowTitle("2D Test App"); glEnable(GL_TEXTURE_2D); glDisable(GL_DEPTH_TEST); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, 800, 600, 0, 0, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); ILuint texid; ILboolean success; GLuint image; ilGenImages(1, &texid); ilBindImage(texid); ilLoadImage("bluebutton.tga"); ilConvertImage(IL_RGB, IL_UNSIGNED_BYTE); glGenTextures(1, &image); glBindTexture(GL_TEXTURE_2D, image); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, ilGetInteger(IL_IMAGE_BPP), ilGetInteger(IL_IMAGE_WIDTH),ilGetInteger(IL_IMAGE_HEIGHT), 0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE,ilGetData()); while(running) { glClear( GL_COLOR_BUFFER_BIT ); glBegin(GL_QUADS); glTexCoord2i(0, 0); glVertex2i(0, 0); glTexCoord2i(0, 1); glVertex2i(0, ilGetInteger(IL_IMAGE_WIDTH)); glTexCoord2i(1, 1); glVertex2i(ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_WIDTH)); glTexCoord2i(1, 0); glVertex2i(ilGetInteger(IL_IMAGE_WIDTH), 0); glEnd(); glfwSwapBuffers(); running = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam( GLFW_OPENED); } ilDeleteImages(1, &texid); glDeleteTextures(1, &image); glfwTerminate(); return 0; }
This only displays a white box. Where am i going wrong, and is there a good tutorial on simple 2d image loading and display for opengl. Also, why would my 800x600 background be resized? Thanks for any input.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by schragnasher
    ilGenImages(1, &texid);
ilBindImage(texid);
ilLoadImage("bluebutton.tga");
ilConvertImage(IL_RGB, IL_UNSIGNED_BYTE);
glGenTextures(1, ℑ);
glBindTexture(GL_TEXTURE_2D, image);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, ilGetInteger(IL_IMAGE_BPP),
ilGetInteger(IL_IMAGE_WIDTH),ilGetInteger(IL_IMAGE_HEIGHT),
0, ilGetInteger(IL_IMAGE_FORMAT),
GL_UNSIGNED_BYTE,ilGetData());
What would be wrong with texid = ilutGLLoadImage(bluebutton.tga"); instead of all that? Far less to get wrong, at any rate...

Quote:
Also, why would my 800x600 background be resized?
By default, OpenGL only supports textures with power-of-2 dimensions (i.e. 256x256, 1024x1024, etc). Newer graphics cards usually support the ARB_texture_non_power_of_two extension, which allows you to avoid this requirement.

Share this post


Link to post
Share on other sites
Quote:
Original post by schragnasher
if thats the case is there any way to circumvent Devil from resizing so i can use the extension?
I don't recall DevIL ever resizing by itself when you load with your method, but then again, I haven't used DevIL for a very long time...

Share this post


Link to post
Share on other sites
according to teh DevIL documentation

Quote:
DevIL allows the use of arbitrarily-sized images, but OpenGL only works with images that have dimensions that are powers of 2, for optimization purposes. If an image has dimensions that are not powers of 2, DevIL will resize the image before sending it to OpenGL.


This reduces quality of my image. I was trying to skip over the DevIL code to setup a OGL texture automatically but stripping out the data and sending it to OGl myself using the rectangle extension, which seems to be what the code in the wiki is doing, just cant get it to work.

This is an update to teh above code which fixes one problem, at first it was resizing the textures TREMENDOUSLY because it was thinking my max texture size was 256x256, but i fixed that, its not as ugly now, but still not what it should be because of the ay Devil squares the images sent to OGL.

Quote:

#include<GL/glfw.h>
#include<IL/il.h>
#include<IL/ilu.h>
#include<IL/ilut.h>
#include"glext.h"
int main()
{
bool running = true;
glfwInit();
ilInit();
iluInit();
glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE,GL_TRUE);
glfwOpenWindow( 800, 600, 0, 0, 0, 0, 0, 0, GLFW_WINDOW );
ilutRenderer(ILUT_OPENGL);
glfwSetWindowTitle("2D Test App");
glEnable(GL_TEXTURE_RECTANGLE_ARB);
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, 800, 600, 0, 0, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

ILuint texid;
ILboolean success;
GLuint image;

ilGenImages(1, &texid);
ilBindImage(texid);
ilLoadImage("background.bmp");
//ilutGLLoadImage("background.bmp");
//ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);
glGenTextures(1, & image);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, image);
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB,0,32,800,600,0, GL_RGBA, GL_UNSIGNED_BYTE,ilGetData());

while(running)
{
glClear( GL_COLOR_BUFFER_BIT );
glBegin(GL_QUADS);
glTexCoord2i(0,1);
glVertex2i(0,600);
glTexCoord2i(1,1);
glVertex2i(800,600);
glTexCoord2i(1,0);
glVertex2i(800,0);
glTexCoord2i(0,0);
glVertex2i(0,0);
glEnd();
glfwSwapBuffers();
running = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam( GLFW_OPENED);
}
ilDeleteImages(1, &texid);
glDeleteTextures(1, & image);
glfwTerminate();
return 0;
}

Share this post


Link to post
Share on other sites
Quote:
Original post by schragnasher
This is an update to teh above code which fixes one problem, at first it was resizing the textures TREMENDOUSLY because it was thinking my max texture size was 256x256, but i fixed that, its not as ugly now, but still not what it should be because of the ay Devil squares the images sent to OGL.
Quote:

ilGenImages(1, &texid);
ilBindImage(texid);
ilLoadImage("background.bmp");
//ilutGLLoadImage("background.bmp");
//ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);
glGenTextures(1, & image);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, image);
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB,0,32,800,600,0, GL_RGBA, GL_UNSIGNED_BYTE,ilGetData());
DevIL is not resizing your image there, because DevIL is not sending your texture to OpenGL, you are doing that manually. If your image is still resized, it must be happening elsewhere.

Quote:
Original post by schragnasher
is SOIL a better solution for image loading? I can switch over to SOIL. I just need to be able to load non square textures correctly.
SOIL allows rectangular textures, I requested that support myself. However, I am not sure that it supports the newer NPOT extension.

Share this post


Link to post
Share on other sites
Quote:
Original post by swiftcoder
Quote:
Original post by schragnasher
This is an update to teh above code which fixes one problem, at first it was resizing the textures TREMENDOUSLY because it was thinking my max texture size was 256x256, but i fixed that, its not as ugly now, but still not what it should be because of the ay Devil squares the images sent to OGL.
Quote:

ilGenImages(1, &texid);
ilBindImage(texid);
ilLoadImage("background.bmp");
//ilutGLLoadImage("background.bmp");
//ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);
glGenTextures(1, & image);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, image);
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB,0,32,800,600,0, GL_RGBA, GL_UNSIGNED_BYTE,ilGetData());
DevIL is not resizing your image there, because DevIL is not sending your texture to OpenGL, you are doing that manually. If your image is still resized, it must be happening elsewhere.

Quote:
Original post by schragnasher
is SOIL a better solution for image loading? I can switch over to SOIL. I just need to be able to load non square textures correctly.
SOIL allows rectangular textures, I requested that support myself. However, I am not sure that it supports the newer NPOT extension.


My bad im prolly being confusing, the code iv posted isnt resizing the image, its not displaying it at all. If i use the DEVIL code
Quote:
ilutGLLoadImage("background.bmp");
instead of the GL code it resizes it.

Quote:
You should call glGetError here and there.
glTexImage2D will likely blow an error when you give 32

glTexImage2D(GL_TEXTURE_RECTANGLE_ARB,0,32,800,600,0, GL_RGBA, GL_UNSIGNED_BYTE,ilGetData());

Texture Precision
http://www.opengl.org/wiki/index.php/Common_Mistakes#Texture_Precision

Ill look into the GL code more, i think that will solve my problem in the end, but i changed 32 to GL_RGBA8 and still had an issue, thanks for the link thought ill check deeper into this, or just try and incorporate soil.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!