PDA

View Full Version : basic texture mapping



sajis997
11-10-2014, 10:19 AM
Hello folks,

Any there any problem with the following code:




void loadTextures()
{

glActiveTexture(GL_TEXTURE0);

int textureWidth = 0;
int textureHeight = 0;
int channels = 0;

GLubyte *texData = SOIL_load_image("images/brick1.tga",&textureWidth,
&textureHeight,
&channels,
SOIL_LOAD_AUTO);

if(texData == NULL)
{
std::cerr << "Error loading image: " << std::endl;
exit(EXIT_FAILURE);
}

glGenTextures(1,&cubeTextureID);
glBindTexture(GL_TEXTURE_2D,cubeTextureID);
glTexStorage2D(GL_TEXTURE_2D,1,GL_RGBA8,textureWid th,textureHeight);

glTexSubImage2D(GL_TEXTURE_2D,0,0,0,textureWidth,t extureHeight,GL_RGBA,GL_UNSIGNED_BYTE,BUFFER_OFFSE T(texData));
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);


//free the image data
SOIL_free_image_data(texData);
}



The application crashes at glTexSubImage2D(....) command. I recall that i had similar issues before and it was widely discussed in the forum and i have tried to retrieve those discussion and did not find it. Are forum contents are cleared after certain time old ?

Any way, can you point to the issue that is causing the crash and refer me some explanation once again please ?

Thanks

DragonForce99
11-10-2014, 10:46 AM
you are using GL_RGBA
are sure that your chanel is 32?
are you using jpg image you most check channel first
check the width an height

sajis997
11-10-2014, 10:59 AM
Hi

In the debugger i got the following value for channels , image width and image height. I am using .tga image format as you can see from the snippet:

channel - 3
width = 1024
height = 1024

DragonForce99
11-10-2014, 01:00 PM
if channel = 3
us GL_RGB

channel 4 Use RGBA

DragonForce99
11-10-2014, 01:02 PM
channel men how many channel each pixel
Channel 1 = R-Red
Channel 2 = G-Green
Channel 3 = B-Blue
Channel 4 = A-Alpha

sajis997
11-25-2014, 09:57 AM
Hi ,

Check the following function :



void glTexStorage2D( GLenum target,
GLsizei levels,
GLenum internalformat,
GLsizei width,
GLsizei height);



void glTexSubImage2D( GLenum target,
GLint level,
GLint xoffset,
GLint yoffset,
GLsizei width,
GLsizei height,
GLenum format,
GLenum type,
const GLvoid * pixels);


Both the above function has level as the parameter . Could explain the difference between them ?

Thanks

GClements
11-25-2014, 10:28 AM
Both the above function has level as the parameter . Could explain the difference between them ?

The "levels" parameter to glTexStorage is the total number of mipmap levels. The "level" parameter to glTexSubImage is the level to which the data is uploaded.