Results 1 to 7 of 7

Thread: Help with loading image

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2009
    Posts
    7

    Help with loading image

    This is my code:
    Code :
    #include "player.h"
    #include <gl/gl.h>
    #include "SOIL.h"
     
    //Physical Variables
    GLint x=0;
    GLint y=0;
    GLint z=0;
     
    GLint x_origin=32;
    GLint y_origin=32;
     
    GLdouble angle=0;
     
    int i;
     
    //Sprite Variables
     
    GLint width[0];
    GLint height[0];
    GLint miplevel = 0;
     
    int image_index;
     
    GLint player_image[0];
    GLint player_animation[0];
     
    bool loadPlayerImages(const char* dir)
    {
     
        player_image[0] = SOIL_load_OGL_texture
    	(
    		dir,
    		SOIL_LOAD_AUTO,
    		SOIL_CREATE_NEW_ID,
    		SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
    	);
    	glGetTexLevelParameteriv(GL_TEXTURE_2D, miplevel, GL_TEXTURE_WIDTH, &amp;width[0]);
        glGetTexLevelParameteriv(GL_TEXTURE_2D, miplevel, GL_TEXTURE_HEIGHT, &amp;height[0]);
     
    }
     
    void player::create(int type)
    {
    loadPlayerImages("img/0.bmp");
    //width[0]=64;
    //height[0]=64;
    }
     
    void player::step()
    {
    image_index=0;
    //x+=1;
    }
     
    void player::draw()
    {
    //glRotated(angle,0,0,32);
    //glColor3i(1,1,1);
     
    glBindTexture(GL_TEXTURE_2D, player_image[0]);
     
    glBegin(GL_QUADS); //begin the four sided shape
    glTexCoord2i(0,0);                                      glVertex2i(x, y); //first corner at -0.5, -0.5
    glTexCoord2i(0,height[image_index]);                    glVertex2i(x, y+height[image_index]); //second corner at -0.5, 0.5
    glTexCoord2i(width[image_index],height[image_index]);   glVertex2i(x+width[image_index], y+height[image_index]); //third corner at 0.5, 0.5
    glTexCoord2i(width[image_index],0);                     glVertex2i(x+width[image_index], y); //fourth corner at 0.5, -0.5
    glEnd();
     
    }

    Its a class for a player object thats supposed to load a image using SOIL, but I can't get it to draw the textured quad. Instead it draws a single colored block.

    Can anyone help me?



    ~Justin123

  2. #2
    Member Newbie
    Join Date
    Jun 2009
    Posts
    47

    Re: Help with loading image

    im pretty sure this is the bug

    GLint player_image[0]; //this means you just allocated a GLint array that holds 0 GLints you should change it to
    GLint player_image[1];

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2009
    Posts
    7

    Re: Help with loading image

    It still just draws a blue block.

  4. #4
    Member Contributor
    Join Date
    Jul 2009
    Posts
    53

    Re: Help with loading image

    Have you enabled texturing?

    glEnable( GL_TEXTURE_2D );

  5. #5
    Junior Member Newbie
    Join Date
    Nov 2009
    Posts
    7

    Re: Help with loading image

    yes I have enabled 2d textures

  6. #6
    Member Contributor
    Join Date
    Jul 2009
    Posts
    53

    Re: Help with loading image

    You're tiling the texture over the quad [width]x[height] times. glTexCoord2i, like the float version, expects 0,0 to 1,1 to correctly map the texture.

    Code :
    glBegin(GL_QUADS); //begin the four sided shape
      glTexCoord2i(0,0);  glVertex2i(x, y); //first corner at -0.5, -0.5
      glTexCoord2i(0,1);  glVertex2i(x, y+height[image_index]); //second corner at -0.5, 0.5
      glTexCoord2i(1,1);  glVertex2i(x+width[image_index], y+height[image_index]); //third corner at 0.5, 0.5
      glTexCoord2i(1,0);  glVertex2i(x+width[image_index], y); //fourth corner at 0.5, -0.5
    glEnd();

  7. #7
    Junior Member Newbie
    Join Date
    Nov 2009
    Posts
    7

    Re: Help with loading image

    Ok, now it works! Thanks a bunch.

    ~Justin123

Similar Threads

  1. Image Loading Library for loading image textures
    By jitendra2896 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 08-03-2017, 12:13 AM
  2. Loading a image
    By imported_Justin in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 12-21-2010, 12:36 PM
  3. Loading an image??
    By Creative Mind in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 08-20-2009, 11:13 AM
  4. Loading an image
    By Erin C. in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 11-02-2008, 04:28 AM
  5. Replies: 2
    Last Post: 07-28-2003, 07:30 PM

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