Here’s the thing: I don’t get any SOIL or OpenGL errors, and yet the image I load isn’t displayed.
Texture load & draw code:
// textures is std::map<std::string, GLuint>
if (textures.find(imagepath)==textures.end())
{
textures[imagepath] = SOIL_load_OGL_texture(imagepath.c_str(),
SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID,0);
owner->setdbgstr("loading texture...");
}
else if(textures[imagepath]!=0)
{
owner->setdbgstr("texture is loaded successfully");
oglImage(textures[imagepath]);
std::string error = "toll!";
GLenum laste = GL_NO_ERROR;
while(true)
{
GLenum err = glGetError();
if ( err == GL_NO_ERROR )
break;
if ( err == laste )
{
errr = "Error with glGetError()";
break;
}
laste = err;
error = "OpenGL error: "+std::to_string(err);
}
owner->setdbgstr(error);
}
else
{
owner->setdbgstr("Error loading image: " + std::string(SOIL_last_result(),0,3));
}
oglImage:
void oglImage(GLuint gluimage)
{
double ww, hh;
ww=100.0;
hh=100.0;
double r = 1.0, g = 1.0, b = 1.0, a = 1.0;
double points[] =
{
0.0, 0.0, r, g, b, a, 0.0, 0.0,
0.0, hh, r, g, b, a, 0.0, 1.0,
ww, hh, r, g, b, a, 1.0, 1.0,
ww, 0.0, r, g, b, a, 1.0, 0.0
};
GLuint vbo;
glGenBuffersARB(1, &vbo);
glBindBufferARB(GL_ARRAY_BUFFER, vbo);
glBufferDataARB(GL_ARRAY_BUFFER,4 * sizeof(double) * 8,&points[0],GL_STATIC_DRAW);
glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glBindTexture(GL_TEXTURE_2D, gluimage);
glBindBufferARB(GL_ARRAY_BUFFER, vbo);
glVertexPointer(2, GL_DOUBLE, sizeof(double) * 8, NULL);
glTexCoordPointer(2, GL_DOUBLE, sizeof(double) * 8, (void*)(sizeof(double)*6));
glDrawArrays(GL_QUADS, 0, 4);
//glFlush() is called later down the line, other gl elements are drawn just fine
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glDisable(GL_TEXTURE_2D);
}
Another version of oglImage, only draws a white square:
void oglImage(GLuint gluimage)
{
double ww, hh;
ww=100.0;
hh=100.0;
double r = 1.0, g = 1.0, b = 1.0, a = 1.0;
double points[] =
{
0.0, 0.0, r, g, b, a, 0.0, 0.0,
0.0, hh, r, g, b, a, 0.0, 1.0,
ww, hh, r, g, b, a, 1.0, 1.0,
ww, 0.0, r, g, b, a, 1.0, 0.0
};
GLuint vao;
glGenVertexArraysAPPLE(1, &vao);
glBindVertexArrayAPPLE(vao);
GLuint vbo1;
glGenBuffersARB(1, &vbo1);
//vbo1 = image;
glBindBufferARB(GL_ARRAY_BUFFER, vbo1);
//glBindBufferARB(GL_ARRAY_BUFFER, image);
glBindTexture(GL_TEXTURE_2D, gluimage);
glBufferDataARB(GL_ARRAY_BUFFER,4 * sizeof(double) * 8,&points[0],GL_STATIC_DRAW);
glVertexPointer(2, GL_DOUBLE, sizeof(double) * 8, NULL);
glColorPointer(4, GL_DOUBLE, sizeof(double) * 8, (void*)(sizeof(double)*2));
glTexCoordPointer(2, GL_DOUBLE, sizeof(double) * 8, (void*)(sizeof(double)*6));
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glDrawArraysEXT(GL_QUADS, 0, 4);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}