Jump to content
  • Advertisement
Sign in to follow this  
nunosantos

OpenGL Texturing geometrics with DevIL in Windows

This topic is 4257 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

Hello everyone, I made an app in Mac OSX using SDL, OpenGL and Devil. I'm now porting that same app to windows but without SDL. I've been for days trying to discover what is the problem of devil and the texturing of geometrics because i cant just put it working! It loads images, but when its supposed to texture the geometrics nothing happens beside a white quad. I wrote a really basic example to try isolate the problem but i still cant see what is happening This is my small example: <code> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <time.h> // OpenGL includes #include <glut.h> // DevIL includes #include <IL/il.h> #include <IL/ilu.h> #include <IL/ilut.h> GLuint TexID; void Init(void) { ilInit(); ilEnable(IL_CONV_PAL); ilEnable(IL_ORIGIN_SET); iluInit(); ilutEnable(ILUT_OPENGL_CONV); ilutRenderer(ILUT_OPENGL); glEnable(GL_TEXTURE_2D); //glEnable(GL_DEPTH_TEST); //glEnable(GL_CULL_FACE); glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); } void ChangeSize(int w, int h) { float ratio; // Prevent a divide by zero, when window is too short // (you cant make a window of zero width). if(h == 0) h = 1; ratio = 1.0 * w / h; // Reset the coordinate system before modifying glMatrixMode(GL_PROJECTION); glLoadIdentity(); // Set the viewport to be the entire window glViewport(0, 0, w, h); // Set the correct perspective. //gluPerspective(45,ratio,0.1,500); gluPerspective(45,ratio,1,1000); glMatrixMode(GL_MODELVIEW); } void Render(void) { glClearColor(0.0f,0.0f,0.0f,0.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0.0f,0.0f,2.0f,0.0f,0.0f,0.0f,0.0f,1.0f,0.0f); glBindTexture(GL_TEXTURE_2D, TexID); glBegin(GL_QUADS); glTexCoord2f(0,0); glVertex3f(-0.5,-0.5,0); glTexCoord2f(1,0); glVertex3f(-0.5,0.5,0); glTexCoord2f(1,1); glVertex3f(0.5,0.5,0); glTexCoord2f(0,1); glVertex3f(0.5,-0.5,0); glEnd(); glutSwapBuffers(); } void main(int argc, char **argv) { glutInit(&argc, argv); glutInitWindowPosition(0, 0); glutInitWindowSize(800, 600); glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); glutCreateWindow("GLBasicTest"); Init(); ILuint ImgId; ILboolean success; ilGenImages (1, &ImgId); ilBindImage (ImgId); success = ilLoadImage((wchar_t*)"c:/18.jpg"); if (success) { ilConvertImage(IL_RGB,IL_UNSIGNED_BYTE); glGenTextures(1, &TexID); glBindTexture(GL_TEXTURE_2D, TexID); 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()); } else { printf("Couldn load image\n"); } glutReshapeFunc(ChangeSize); glutDisplayFunc(Render); glutIdleFunc(Render); glutMainLoop(); } </code> Can anyone please try to tell me what is going on? Many thx, Nuno

Share this post


Link to post
Share on other sites
Advertisement
Hi,

Taking a quick glance at your code. There looks like you may be displaying the wrong side of the ploygon. Try this as a start.

glFrontFace(GL_CCW); // polygon vertices are in anti-clockwise order
glPolygonMode(GL_FRONT, GL_FILL);

You may also want to cull back faces too.

glEnable(GL_CULL_FACE);
glCullFace(GL_BACK); // cull back facing polygons

MAMEman.

Share this post


Link to post
Share on other sites
Hi
Maybe you could use
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
before loading the texture.

If it doesn't works you could create a 2x2 texture filled with a buffer like
static const int[] = {0xFFFFFFFF, 0, 0xFFFFFFFF, 0};

Anyway there seems to be a wroking sample here
http://www.gamedev.net/community/forums/topic.asp?topic_id=399519

Share this post


Link to post
Share on other sites
Are you are trying to use a non-power-of-two texture without mipmapping and without having the NPOT extension?

You could try using ilutGLLoadImage to see if it's a problem in your gl code.

Share this post


Link to post
Share on other sites
Hi,

I've tried the two kind of images. Doesnt work.

I have also tried ilutGLLoadImage, but it doesnt work too.

Can someone just try the code i posted and see if it is working?

Maybe is something else which is not the code.

I'm already givin in crazy with this.

Thx,

Nuno

Share this post


Link to post
Share on other sites
Hi,

I've just googled "ilLoadImage" and this states that it only take a "char *" as a parameter yet in your code you have casted the "const char *" "c:/18.jpg" to "wchar_t *". Why are you doing this?. Looking it may be that the image is not loading at all!. Just try "c:\\18.jpg" and see if that works.

MAMEman.

Share this post


Link to post
Share on other sites
No, if i take the cast out the compiler will not build.

And i'm sure the image is getting load because the size of it is being displayed right.

:( :(

Share this post


Link to post
Share on other sites
Hmmm,

There is definitely an issue with the image cause I've got it working on my system!. It compiles and displays a textured quad in the middle of the screen. I can't understand why when you take out the cast you would get a compiler error. Humour me and place "C:\\18.jpg" as the parameter to the illoadimage function and see what error(s) you get. Output them in your response.

MAMEman.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!