Jump to content
  • Advertisement
Sign in to follow this  
ishkabible

DevIL issues

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

ok so i had some bad luck with DevIL i while back and wanted to give it another shot. I'm trying to use glfw and DevIL to texture 2 triangles with a texture loaded with ilutGLLoadImage. problem is nothing happens they just show up completely white. not sure what im doing wrong.


#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glfw.h>

#include<IL/il.h>
#include<IL/ilu.h>
#include<IL/ilut.h>

int main() {
ilInit();
iluInit();
ilutInit();
ilutRenderer(ILUT_OPENGL);
glEnable( GL_TEXTURE_2D );
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
int width, height;
int frame = 0;
bool running = true;
GLuint tex = ilutGLLoadImage("Zombie.png");
glfwInit();
if( !glfwOpenWindow( 512, 512, 0, 0, 0, 0, 0, 0, GLFW_WINDOW ) ) {
glfwTerminate();
return 0;
}
glfwSetWindowTitle("GLFW Application");
while(running) {
frame++;
glfwGetWindowSize( &width, &height );
height = height > 0 ? height : 1;
glViewport( 0, 0, width, height );
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
glClear( GL_COLOR_BUFFER_BIT );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective( 65.0f, (GLfloat)width/(GLfloat)height, 1.0f, 100.0f );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
gluLookAt(0.0f, -10.0f, 0.0f,0.0f, 0.0f, 0.0f,0.0f, 0.0f, 1.0f );
glRotatef(frame, 0.25f, 1.0f, 0.75f);
glBegin( GL_TRIANGLES );
glBindTexture(GL_TEXTURE_2D,tex);
glVertex3f(0.0f, 3.0f, -4.0f);
glVertex3f(3.0f, -2.0f, -4.0f);
glVertex3f(-3.0f, -2.0f, -4.0f);
glEnd();
glBegin( GL_TRIANGLES );
glVertex3f(0.0f, 3.0f, -3.0f);
glVertex3f(3.0f, -2.0f, -2.0f);
glVertex3f(-3.0f, -2.0f, 2.0f);
glEnd();
glfwSwapBuffers();
running = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam(GLFW_OPENED);
}
glfwTerminate();
return 0;
}


Share this post


Link to post
Share on other sites
Advertisement
glEnable(GL_TEXTURE_2D);

glTexCoord2f();


Your missing a couple things. OpenGL does not magically know how you want the image to show up, you have to give each vertex a texture coordinate so that it knows what part of the image to use for that triangle.

Share this post


Link to post
Share on other sites
ok silly mistake, i forgot to add the texture coordinates. still no texture is shown. not sure what the issue is. i dont have much to go off of becuase i cant see if there is any texture displaying.


#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glfw.h>

#include<IL/il.h>
#include<IL/ilu.h>
#include<IL/ilut.h>

int main() {
ilInit();
iluInit();
ilutInit();
ilutRenderer(ILUT_OPENGL);
glEnable( GL_TEXTURE_2D );
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
int width, height;
int frame = 0;
bool running = true;
GLuint tex = ilutGLLoadImage("Zombie.png");
glfwInit();
if( !glfwOpenWindow( 512, 512, 0, 0, 0, 0, 0, 0, GLFW_WINDOW ) ) {
glfwTerminate();
return 0;
}
glfwSetWindowTitle("GLFW Application");
while(running) {
frame++;
glfwGetWindowSize( &width, &height );
height = height > 0 ? height : 1;
glViewport( 0, 0, width, height );
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
glClear( GL_COLOR_BUFFER_BIT );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluOrtho2D(0,512,512,0);
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glBindTexture(GL_TEXTURE_2D,tex);
glBegin(GL_QUADS);
//glColor3f(0,1,0);
glTexCoord2i(0, 0); glVertex2i(0, 0);
glTexCoord2i(0, 1); glVertex2i(0, 512);
glTexCoord2i(1, 1); glVertex2i(512, 512);
glTexCoord2i(1, 0); glVertex2i(512, 0);
glEnd();

glfwSwapBuffers();
running = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam(GLFW_OPENED);
}
glfwTerminate();
return 0;
}



edit: i changed it a bit to make it simpler, using 2D graphics now.

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!