PDA

View Full Version : Sth wrong with texture loaded using SOIL



butterfly
01-14-2013, 11:51 PM
Hello.
I suppose that in my code is possibly really small mistake which makes it working wrong. I would like to load png image using soil library and make a texture from it. The problem is that I get information that I loaded picture in right way but on the screen I see only smal square with colour of my picture's left upper corner. Please help me finding my mistake.



#include <stdio.h>
#include <GL/glu.h>
#include <GL/glut.h> // Include the GLUT header file
#include "soil.h"

GLuint usertex;

void renderPrimitive (void) {

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,usertex);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

glBegin(GL_QUADS); // Start drawing a quad primitive
glVertex3f(-0.1f, -0.1f, 0.0f); // The bottom left corner
glVertex3f(-0.1f, 0.1f, 0.0f); // The top left corner
glVertex3f(0.1f, 0.1f, 0.0f); // The top right corner
glVertex3f(0.1f, -0.1f, 0.0f); // The bottom right corner
glEnd();
glDisable(GL_TEXTURE_2D);
}

void display (void) {


glClearColor(1.0f, 0.0f, 0.0f, 1.0f); // Clear the background of our window to red
glDisable(GL_BLEND);
glClear(GL_COLOR_BUFFER_BIT); //Clear the colour buffer (more buffers later on)
glLoadIdentity(); // Load the Identity Matrix to reset our drawing locations

glTranslatef(0.0f, 0.0f, -5.0f); // Push eveything 5 units back into the scene, otherwise we won't see the primitive

renderPrimitive(); // Render the primitive

glFlush(); // Flush the OpenGL buffers to the window
}

void reshape (int width, int height) {
glViewport(0, 0, (GLsizei)width, (GLsizei)height); // Set our viewport to the size of our window
glMatrixMode(GL_PROJECTION); // Switch to the projection matrix so that we can manipulate how our scene is viewed
glLoadIdentity(); // Reset the projection matrix to the identity matrix so that we don't get any artifacts (cleaning up)
gluPerspective(60, (GLfloat)width / (GLfloat)height, 1.0, 100.0); // Set the Field of view angle (in degrees), the aspect ratio of our window, and the new and far planes
glMatrixMode(GL_MODELVIEW); // Switch back to the model view matrix, so that we can start drawing shapes correctly
}


int main (int argc, char **argv) {
glutInit(&argc, argv); // Initialize GLUT
glutInitDisplayMode (GLUT_SINGLE); // Set up a basic display buffer (only single buffered for now)
glutInitWindowSize (500, 500); // Set the width and height of the window
glutInitWindowPosition (100, 100); // Set the position of the window
glutCreateWindow ("You’re first OpenGL Window"); // Set the title for the window

glutDisplayFunc(display); // Tell GLUT to use the method "display" for rendering

glutReshapeFunc(reshape); // Tell GLUT to use the method "reshape" for reshaping




/* load an image file directly as a new OpenGL texture */
usertex = SOIL_load_OGL_texture
(
"you1.png",
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
);
printf("Hello");
/* check for an error during the load process */
if( 0 == usertex )
{
printf( "SOIL loading error: '%s'\n", SOIL_last_result() );
} else {
printf("SOIL load success for user block");
}


glutMainLoop(); // Enter GLUT's main loop
return 0;
}