basic texture mapping

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,textureWidth,textureHeight);

    glTexSubImage2D(GL_TEXTURE_2D,0,0,0,textureWidth,textureHeight,GL_RGBA,GL_UNSIGNED_BYTE,BUFFER_OFFSET(texData));
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,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

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

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

if channel = 3
us GL_RGB

channel 4 Use RGBA

channel men how many channel each pixel
Channel 1 = R-Red
Channel 2 = G-Green
Channel 3 = B-Blue
Channel 4 = A-Alpha

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

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.