PDA

View Full Version : glimg is breaking the opengl context?



Ygyaxthe3rd
05-12-2013, 08:03 PM
My code is breaking when I use the glMatrixMode( GL_PROJECTION ) command, and I think this is because the context is breaking when I try to load a picture using glimg. Here is my code:



#include <stdlib.h>
#include <stdio.h>
#include <memory>
#include <glload/gl_all.h>
#include <glload/gll.hpp>
#include <glimg/glimg.h>
#include <GL/glfw.h>
#include <glimg/TextureGeneratorExceptions.h>

int main()
{
int width, height;
int frame = 0;
bool running = true;

glfwInit();

if( !glfwOpenWindow( 512, 512, 0, 0, 0, 0, 0, 0, GLFW_WINDOW ) )
{
glfwTerminate();
return 0;
}

glfwSetWindowTitle("GLFW Application");

//////////////////////////////////////////////////////////////////////////////////
if(glload::LoadFunctions() == glload::LS_LOAD_FAILED)
{
printf("glload failure.\n");
running = false;
return 0;
}

GLuint theTexture = 0;

try{
std::auto_ptr<glimg::ImageSet> pImgSet(glimg::loaders::stb::LoadFromFile("test.png"));
theTexture = glimg::CreateTexture(pImgSet.get(), 0);
}catch(glimg::loaders::stb::StbLoaderException &e){
printf("Image file loading failed.\n");
}catch(glimg::TextureGenerationException &e){
printf("Texture creation failed.\n");
}

printf("Texture creation successful.\n");
/////////////////////////////////////////////////////////////////////////////////

while(running)
{
frame++;

glfwGetWindowSize( &width, &height );
height = height > 0 ? height : 1;

glViewport( 0, 0, width, height );

glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
glClear( GL_COLOR_BUFFER_BIT );

glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective( 65.0f, (GLfloat)width/(GLfloat)height, 1.0f, 100.0f );

// Draw some rotating garbage
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
gluLookAt(0.0f, -10.0f, 0.0f,
0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f );

//glTranslatef( 1.0f, 1.0f, 0.0f );
glRotatef(frame, 0.25f, 1.0f, 0.75f);
glBegin( GL_TRIANGLES );
glColor3f(0.1f, 0.0f, 0.0f );
glVertex3f(0.0f, 3.0f, -4.0f);
glColor3f(0.0f, 1.0f, 0.0f );
glVertex3f(3.0f, -2.0f, -4.0f);
glColor3f(0.0f, 0.0f, 1.0f );
glVertex3f(-3.0f, -2.0f, -4.0f);
glEnd();
glBegin( GL_TRIANGLES );
glColor3f(0.0f, 0.1f, 0.0f );
glVertex3f(0.0f, 3.0f, -3.0f);
glColor3f(0.0f, 0.0f, 1.0f );
glVertex3f(3.0f, -2.0f, -2.0f);
glColor3f(1.0f, 0.0f, 0.0f );
glVertex3f(-3.0f, -2.0f, 2.0f);
glEnd();

glfwSwapBuffers();

// exit if ESC was pressed or window was closed
running = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam( GLFW_OPENED);
}

glfwTerminate();

return 0;
}


If I comment out glMatrixMode( GL_PROJECTION ) to the last glEnd(), the program runs, but I am trying to get the program to load an image as well as display the triangle demo.

Alfonse Reinheart
05-12-2013, 08:09 PM
You say "the context is breaking". What error do you get? What GPU are you using? What OpenGL version are you running? And more importantly, what happens if you comment out the glimg stuff?

Ygyaxthe3rd
05-12-2013, 08:42 PM
The console returns:


Texture creation successful.

Process returned -1073741819 (0xC0000005) execution time : 1.631 s
Press any key to continue.


I am using an NVIDIA GeForce GT 635M GPU, and OpenGL version 4.0

If I comment out the glimg image loading stuff and the include files for it then the program runs the triangle demo properly. If I don't comment out the header for the glimg stuff, then the program crashes.

Alfonse Reinheart
05-12-2013, 10:07 PM
Wait. Just including the header causes the crash?

I can't reproduce the crash on my machine (I tried running the 0.4.4 release). I copied your code into a test application and it seems to work just fine.

Can you narrow down exactly which glimg header is causing the problem?

Ygyaxthe3rd
05-13-2013, 02:05 PM
I managed to get the program to work! For some reason commenting out


#include <glload/gl_all.h>

stopped the crashes.

Alfonse Reinheart
05-13-2013, 03:14 PM
That makes no sense. If you don't include the GL Load header, then your code is going to start failing to compile once you use anything that's not from GL 1.1.

Ygyaxthe3rd
05-13-2013, 05:40 PM
I am still including the


#include <glload/gll.hpp>

header, so maybe that is the header I need? I'm not sure. Is there anything wrong with excluding the header that is causing it to crash if its working without it?

Alfonse Reinheart
05-13-2013, 06:04 PM
The reason your code is working is because glfw.h includes the gl.h header. But the gl.h header will only contain the core 1.1 stuff (on Windows at least). And nothing you're using is outside that range. Just attempt to directly call any OpenGL function after GL 1.1. Like, say, glCreateProgram(). You'll get a compiler error. Or just use any post-1.1 enumerator, like GL_TEXTURE_3D.

As stated in the docs, gll.hpp is just for the basic system. It's where you get `glload::LoadFunctions` from. The OpenGL headers are all of the form `gl_*.h` or `gl_*.hpp`.

Ygyaxthe3rd
05-13-2013, 06:25 PM
What can I do to fix the fact that the header file is causing the program to crash? Is is something in the program? or do I need to update some OpenGL files in my compiler?

Alfonse Reinheart
05-13-2013, 07:54 PM
Like I said, I can't reproduce it on my machine. So I don't know what's going on. Earlier, I asked if you could narrow down exactly which header from glimg it was that was causing the problem. You already said that everything works if you take out the glimg headers (and code, of course). So there seems to be some interaction there.

You might also try making sure to include glfw.h last.