PDA

View Full Version : Trouble loading textures with glimg



Ygyaxthe3rd
04-27-2013, 12:23 PM
I've been trying to use the Unofficial OpenGL SDK, but when I attempt to use the image loading library, I keep getting errors. Here is my code:



1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <memory>
4 #include <glload/gl_all.h>
5 #include <glload/gll.hpp>
6 #include <glimg/glimg.h>
7 #include <GL/glfw.h>
8
9 using namespace glimg;
10
11 int main()
12 {
13 int width, height;
14 int frame = 0;
15 bool running = true;
16
17 glfwInit();
18
19 if( !glfwOpenWindow( 1600, 900, 0, 0, 0, 0, 0, 0, GLFW_FULLSCREEN ) )
20 {
21 glfwTerminate();
22 return 0;
23 }
24
25 glfwSetWindowTitle("GLFW Application");
26
27 //////////////////////////////////////////////////////////////////////////////////
28 if(glload::LoadFunctions() == glload::LS_LOAD_FAILED)
29 {
30 running = false;
31 return 0;
32 }
33
34 GLuint theTexture = 0;
35
36 try
37 {
38 std::auto_ptr<glimg::ImageSet> pImgSet(glimg::loaders::stb::LoadFromFile("TestImage.png"));
39 theTexture = glimg::CreateTexture(pImgSet.get(), 0);
40 }
41 catch(glimg::loaders::stb::StbLoaderException &e)
42 {
43 printf("Image file loading failed.");
44 }
45 catch(glimg::TextureGenerationException &e)
46 {
47 printf("Texture creation failed.");
48 }
49 /////////////////////////////////////////////////////////////////////////////////
50
51 while(running)
52 {
53 frame++;
54
55 glfwGetWindowSize( &width, &height );
56 height = height > 0 ? height : 1;
57
58 glViewport( 0, 0, width, height );
59
60 glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
61 glClear( GL_COLOR_BUFFER_BIT );
62
63 glMatrixMode(GL_PROJECTION);
64 glLoadIdentity();
65 glOrtho(0.0,width,height,0.0,-1.0,1.0);
66
67 glfwSwapBuffers();
68
69 // exit if ESC was pressed or window was closed
70 running = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam( GLFW_OPENED);
71 }
72
73 glfwTerminate();
74
75 return 0;
76 }


Here are the errors that I cant seem to fix:



C:\Users\Colin\Documents\CompDev\C++\TextureTest\m ain.cpp||In function 'int main()':|
C:\Users\Colin\Documents\CompDev\C++\TextureTest\m ain.cpp|45|error: expected type-specifier|
C:\Users\Colin\Documents\CompDev\C++\TextureTest\m ain.cpp|45|error: expected unqualified-id before '&' token|
C:\Users\Colin\Documents\CompDev\C++\TextureTest\m ain.cpp|45|error: expected ')' before '&' token|
C:\Users\Colin\Documents\CompDev\C++\TextureTest\m ain.cpp|45|error: expected '{' before '&' token|
C:\Users\Colin\Documents\CompDev\C++\TextureTest\m ain.cpp|45|error: 'e' was not declared in this scope|
C:\Users\Colin\Documents\CompDev\C++\TextureTest\m ain.cpp|45|error: expected ';' before ')' token|
||=== Build finished: 6 errors, 0 warnings (0 minutes, 1 seconds) ===|


I've tried commenting out the offending catch(), but the program always crashes before it can get to the main loop, and never due to failed image file loading.

Alfonse Reinheart
04-27-2013, 06:49 PM
It seems I forgot to have `glimg/TextureGenerator.h` #include `glimg/TextureGeneratorExceptions.h`. So you'll have to include that manually for the time being, until a new version with the fix comes out.

Ygyaxthe3rd
04-27-2013, 09:15 PM
I included the header file, and the program now builds, but when I try to run it it crashes on line 63 where I call glMatrixMode(). The console returns this after closing the application:



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


I changed lines 63 to 65 and added some stuff which doesn't seem to have fixed this issue. This is the revised version:



glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0,width,height,0.0,-1.0,1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

Ygyaxthe3rd
04-28-2013, 12:27 PM
*bump* Can someone help me with this?