• Create Account

### #Actualic0de

Posted 30 September 2012 - 06:57 PM

I don't see anything wrong with you code but try setting:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);


in case your texture is too small and is being mapped somewhere you cant see.

also since you're already using SDL you might want to try using SDL_image for image loading instead of SOIL. you use SDL_image to load an image to a surface and then find the format and number of colors. then you use glteximage2d to get the image from surface->pixels.

surface = IMG_Load("texture.png");

GLenum texture_format;
GLint  nOfColors;
GLuint texture;
nOfColors = surface->format->BytesPerPixel;

glGenTextures( 1, &texture );
glBindTexture( GL_TEXTURE_2D, texture );

if (nOfColors == 4)	 // contains an alpha channel
{
{
texture_format = GL_RGBA;
}
else
{
texture_format = GL_BGRA;
}
}
else if (nOfColors == 3)	 // no alpha channel
{
{
texture_format = GL_RGB;
}
else
{
texture_format = GL_BGR;
}
}

glTexImage2D( GL_TEXTURE_2D, 0, nOfColors, surface->w, surface->h, 0, texture_format, GL_UNSIGNED_BYTE, surface->pixels );

SDL_FreeSurface(surface);


### #2ic0de

Posted 30 September 2012 - 06:57 PM

I don't see anything wrong with you code but try setting:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);


in case your texture is too small and is being mapped somewhere you cant see.

also since you're already using SDL you might want to try using SDL_image for image loading instead of SOIL. you use SDL_image to load an image to a surface and then find the format and number of colors. then you use glteximage2d to get the image from surface->pixels.

surface = IMG_Load("texture.png");

GLenum texture_format;
GLint  nOfColors;
GLuint texture;
nOfColors = surface->format->BytesPerPixel;

glGenTextures( 1, &texture );
glBindTexture( GL_TEXTURE_2D, texture );

if (nOfColors == 4)	 // contains an alpha channel
{
{
texture_format = GL_RGBA;
}
else
{
texture_format = GL_BGRA;
}
}
else if (nOfColors == 3)	 // no alpha channel
{
{
texture_format = GL_RGB;
}
else
{
texture_format = GL_BGR;
}
}

glTexImage2D( GL_TEXTURE_2D, 0, nOfColors, surface->w, surface->h, 0, texture_format, GL_UNSIGNED_BYTE, surface->pixels );


### #1ic0de

Posted 30 September 2012 - 06:55 PM

I don't see anything wrong with you code but try setting:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);


in case your texture is too small and is being mapped somewhere you cant see.

also since you're already using SDL you might want to try using SDL_image for image loading instead of SOIL. you use SDL_image to load an image to a surface and then find the format and number of colors. then you use glteximage2d to get the image from surface->pixels.

surface = IMG_Load("texture.png");

GLenum texture_format;
GLint  nOfColors;
GLuint texture;
nOfColors = surface->format->BytesPerPixel;

if (nOfColors == 4)	 // contains an alpha channel
{
{
texture_format = GL_RGBA;
}
else
{
texture_format = GL_BGRA;
}
}
else if (nOfColors == 3)	 // no alpha channel
{
{
texture_format = GL_RGB;
}
else
{
texture_format = GL_BGR;
}
}

glTexImage2D( GL_TEXTURE_2D, 0, nOfColors, surface->w, surface->h, 0, texture_format, GL_UNSIGNED_BYTE, surface->pixels );


PARTNERS