Results 1 to 3 of 3

Thread: Don't see my texture on cube, SOIL

  1. #1
    Newbie Newbie
    Join Date
    Oct 2013
    Posts
    3

    Don't see my texture on cube, SOIL

    Hey guys,

    I have a problem with my texture. I coded a cube and uses the SOIL library. But the texture will be not shown. I don't know where my bug is :/

    Here is the code:
    Code :
    #include <math.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <GLUT/glut.h>
    #include "SOIL.h"
     
     
    GLfloat lightPos[4] = {50.0, 30.0 ,0.0, 0.0};
    GLfloat lightAmb[3] = {0.1, 0.1, 0.1};
    GLfloat lightDiff[3] = {1.0, 1.0, 1.0};
     
    /* Variables for gluLookAt */
    GLdouble eyeX = 0.0;
    GLdouble eyeY = 5.0;
    GLdouble eyeZ = 25.0;
    GLdouble centerX = 0.0;
    GLdouble centerY = 0.0;
    GLdouble centerZ = 0.0;
    GLdouble upX = 0.0;
    GLdouble upY = 1.0;
    GLdouble upZ = 0.0;
     
    GLdouble angleLookAt = 0.0;
    GLdouble transX = 0.0;
    GLdouble transY = 0.0;
    GLdouble transZ = -1.0;
     
    /* Global variables */
    GLfloat angle = 0.0;
    GLfloat ratio = 0.0;
    GLfloat fraction = 0.3;
    GLint active = 0;
    GLfloat deltaAngle = 0.0;
    GLint mouseCoordX = 0;
    GLint mouseCoordY = 0;
     
    GLuint	texture[1];			// Storage For One Texture ( NEW )
     
     
     
    int LoadGLTextures()
    {
     
    	texture[0] = SOIL_load_OGL_texture
        (
         "NeHe.bmp",
         SOIL_LOAD_AUTO,
         SOIL_CREATE_NEW_ID,
         SOIL_FLAG_INVERT_Y
         );
     
    	if(texture[0] == 0)
    		return false;
     
     
    	// Typical Texture Generation Using Data From The Bitmap
    	glBindTexture(GL_TEXTURE_2D, texture[0]);
    	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
     
    	return true;										// Return Success
    }
     
     
     
    void changeSize(int w, int h) {
    	if(h == 0) h = 1;
    	float ratio = 1.0* w / h;
     
    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
        glViewport(0, 0, w, h);
    	gluPerspective(25, ratio, 1, 1000);
    	glMatrixMode(GL_MODELVIEW);
    }
     
     
    void renderScene(void) {
    	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        centerX = eyeX + transX;
        centerY = eyeY + transY;
        centerZ = eyeZ + transZ;
    	glLoadIdentity();
        gluLookAt(	eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ);
     
    	glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmb);
    	glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiff);
     
    	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
     
        glPushMatrix();
        glTranslatef(0.0f,4.0f,-5.0f);
     
    	glRotatef(0.3f,1.0f,0.0f,0.0f);
    	glRotatef(0.2f,0.0f,1.0f,0.0f);
    	glRotatef(0.4f,0.0f,0.0f,1.0f);
     
    	glBindTexture(GL_TEXTURE_2D, texture[0]);
     
    	glBegin(GL_QUADS);
        // Front Face
        glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);
        glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);
        glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);
        glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);
        // Back Face
        glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
        glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);
        glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);
        glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
        // Top Face
        glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);
        glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,  1.0f,  1.0f);
        glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,  1.0f,  1.0f);
        glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);
        // Bottom Face
        glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
        glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
        glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);
        glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);
        // Right face
        glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
        glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);
        glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);
        glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);
        // Left Face
        glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
        glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);
        glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);
        glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);
    	glEnd();
        glPopMatrix();
     
    	glutSwapBuffers();
    }
     
    int main(int argc, char **argv) {
    	// por inicializacao aqui
    	glutInit(&argc, argv);
    	glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
    	glutInitWindowPosition(0,0);
    	glutInitWindowSize(1440,790);
    	glutCreateWindow("Texture");
     
    	// por registo de funcoes aqui
    	glutDisplayFunc(renderScene);
     
    	glutIdleFunc(renderScene);
    	glutReshapeFunc(changeSize);
     
    	// alguns settings para OpenLG
        glEnable(GL_TEXTURE_2D);							// Enable Texture Mapping ( NEW )
    	glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
    	glEnable(GL_DEPTH_TEST);
    	glEnable(GL_LIGHTING);
    	glEnable(GL_LIGHT0);
    	glEnable(GL_COLOR_MATERIAL);
     
    	glutMainLoop();
     
    	return 0;
    }

    Thanks!!

  2. #2
    Senior Member Regular Contributor uwi2k2's Avatar
    Join Date
    Mar 2011
    Posts
    138
    hi there,

    i canīt see where you are calling the func:

    LoadGLTextures()

    do you ?


    If you do not call this function you will never ever have a texture.

    cu
    uwi
    uwi2k2 - OpenGL Trainer: www.opengl-trainer.com
    ---------------------------------------------------------
    The OpenGL and VULKAN Podcast ( OpenGL2GO ) : OpenGL & Vulkan Podcast
    ---------------------------------------------------------
    timbling.com - Indie TeamUp

  3. #3
    Newbie Newbie
    Join Date
    Oct 2013
    Posts
    3
    Oh yes, that was my fault! Thanks!

Similar Threads

  1. Texture loaded with SOIL isn't displayed
    By 6krktr in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-15-2017, 08:42 AM
  2. Segmentation fault when loading texture using SOIL
    By Donnie in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 04-01-2015, 06:52 AM
  3. SOIL texture atlas rendering still the same part of image
    By imported_butterfly in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 01-17-2013, 01:12 PM
  4. Sth wrong with texture loaded using SOIL
    By imported_butterfly in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 01-15-2013, 12:51 AM
  5. Texture Mapping/Loading an image using SOIL
    By annette in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 11-16-2011, 10:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean