OpenGL textures trigger error 1281 if SFML is not called
Posted
by
user3714670
on Game Development
See other posts from Game Development
or by user3714670
Published on 2014-08-22T15:31:02Z
Indexed on
2014/08/22
16:37 UTC
Read the original article
Hit count: 287
I am using SOIL to apply textures to VBOs, without textures i could change the background and display black (default color) vbos easily, but now with textures, openGL is giving an error 1281, the background is black and some textures are not applied. but the first texture IS applied (nothing else is working though).
The strange thing is : if i create a dummy texture with SFML in the same program, all other textures do work. So i guess there is something i forgot in the texture creation/application, if someone could enlighten me.
Here is the code i use to load textures, once loaded it is kept in memory, it mostly comes from the example of SOIL :
texture = SOIL_load_OGL_single_cubemap(
filename,
SOIL_DDS_CUBEMAP_FACE_ORDER,
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_POWER_OF_TWO
| SOIL_FLAG_MIPMAPS
| SOIL_FLAG_DDS_LOAD_DIRECT
);
if( texture > 0 )
{
glEnable( GL_TEXTURE_CUBE_MAP );
glEnable( GL_TEXTURE_GEN_S );
glEnable( GL_TEXTURE_GEN_T );
glEnable( GL_TEXTURE_GEN_R );
glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP );
glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP );
glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP );
glBindTexture( GL_TEXTURE_CUBE_MAP, texture );
std::cout << "the loaded single cube map ID was " << texture << std::endl;
} else {
std::cout << "Attempting to load as a HDR texture" << std::endl;
texture = SOIL_load_OGL_HDR_texture(
filename,
SOIL_HDR_RGBdivA2,
0,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_POWER_OF_TWO
| SOIL_FLAG_MIPMAPS
);
if( texture < 1 )
{
std::cout << "Attempting to load as a simple 2D texture" << std::endl;
texture = SOIL_load_OGL_texture(
filename,
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_POWER_OF_TWO
| SOIL_FLAG_MIPMAPS
| SOIL_FLAG_DDS_LOAD_DIRECT
);
}
if( texture > 0 ) {
// enable texturing
glEnable( GL_TEXTURE_2D );
// bind an OpenGL texture ID
glBindTexture( GL_TEXTURE_2D, texture );
std::cout << "the loaded texture ID was " << texture << std::endl;
} else {
glDisable( GL_TEXTURE_2D );
std::cout << "Texture loading failed: '" << SOIL_last_result() << "'" << std::endl;
}
}
and how i apply it when drawing :
GLuint TextureID = glGetUniformLocation(shaderProgram, "myTextureSampler");
if(!TextureID)
cout << "TextureID not found ..." << endl;
// glEnableVertexAttribArray(TextureID);
glActiveTexture(GL_TEXTURE0);
if(SFML)
sf::Texture::bind(sfml_texture);
else {
glBindTexture (GL_TEXTURE_2D, texture);
// glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1024, 768, 0, GL_RGB, GL_UNSIGNED_BYTE, &texture);
}
glUniform1i(TextureID, 0);
I am not sure that SOIL is adapted to my program as i want something as simple as possible (i used sfml's texture object which was the best but i can't anymore), but if i can get it to work it would be great.
© Game Development or respective owner