g++glfwg++4.8devil

How to compile with DevIL?


I'm trying to get a proper setup for 3D programs, and the next step is a texture loader. I am trying to use DevIL, but I can't seem to get it working, and no explanatory text seems to be up to date.

To start with, I'm just going to include a dump of my project: (Keep in mind that it just happens to be in this state, it's not all relevant; Also note that 'IOUtil.cpp' just defines 'Print', which prints to 'cout'. It didn't seem relevant, so I excluded it.)

Project Structure:

+- bin
+- include
|   +- GLFW
|   |   +- glfw3.h
|   |   +- glfw3native.h
|   +- IL
|   |   +- config.h
|   |   +- config.h.win
|   |   +- devil_internal_exports.h
|   |   +- il.h
|   |   +- il_wrap.h
|   |   +- ilu.h
|   |   +- ilu_region.h
|   |   +- ilut.h
|   |   +- ilut_config.h
+- lib
|   +- unicode
|   |   +- DevIL.dll
|   |   +- DevIL.lib
|   |   +- ILU.dll
|   |   +- ILU.lib
|   |   +- ILUT.dll
|   |   +- ILUT.lib
|   +- DevIL.dll
|   +- DevIL.lib
|   +- ILU.dll
|   +- ILU.lib
|   +- ILUT.dll
|   +- ILUT.lib
|   +- libglfw3dll.a
+- logs
+- src
|   +- Main.exe
+- build.bat
+- run.bat

Main.exe:

#include <GLFW/glfw3.h>
#include <IL/il.h>
#include <IL/ilu.h>
#include <IL/ilut.h>
#include <stdlib.h>
#include <algorithm>

#include "util/IOUtil.cpp"

float SENSITIVITY = 0.25;

float cursorX = 0;
float cursorY = 0;

float camX = 0;
float camY = 0;

static void error_callback(int error, const char* description) {
    Print("GLFW ERROR: " + (std::string)description);
}

static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) {
    if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
        glfwSetWindowShouldClose(window, GL_TRUE);
    }
}

static void cursor_position_callback(GLFWwindow* window, double xpos, double ypos) {
    float dx = xpos - cursorX;
    float dy = -ypos - cursorY;
    cursorX = xpos;
    cursorY = -ypos;

    camX += dx * SENSITIVITY;
    camY += dy * SENSITIVITY;
    if (camX < 0) {
        camX += 360;
    }
    if (camX > 360) {
        camX -= 360;
    }
    camY = std::max(-90.0f, std::min(90.0f, camY));
}

int main(void) {
    glfwSetErrorCallback(error_callback); //Set the error callback

    Print("Initializing GLFW");
    if (!glfwInit()) { //If initialization fails, crash
        Print("GLFW initialization failed!");
        exit(EXIT_FAILURE);
    }

    Print("Initializing window");
    GLFWwindow* window = glfwCreateWindow(600, 600, "FPS", NULL, NULL); //Initialize the window

    if (!window) { //If window initialization fails, crash
        Print("Window initialization failed!");
        glfwTerminate(); //Deinitialize
        exit(EXIT_FAILURE);
    }

    ilutRenderer(ILUT_OPENGL); //Bind Texture Loader to Renderer

    glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); //Capture the cursor

    glfwMakeContextCurrent(window); //Create the context
    glfwSwapInterval(1); //Set the swap interval

    glfwSetKeyCallback(window, key_callback); //Set the key callback
    glfwSetCursorPosCallback(window, cursor_position_callback); //Set the cursor callback

    //ilInit();
    //ILuint image;
    //ilGenImages(1, &image);
    //ilBindImage(image);
    //ilLoadImage("data/image.png");

    glEnable(GL_TEXTURE_2D);
    GLuint tex;
    //tex = ilutGLBindTexImage();

    Print("Beginning main loop");
    while (!glfwWindowShouldClose(window)) { //Main loop, ends when window close is requested
        float ratio;
        int width, height;
        glfwGetFramebufferSize(window, &width, &height); //Load the window dimensions
        ratio = width / (float) height; //Calculate the aspect ratio
        glViewport(0, 0, width, height); //Configure the viewport

        glClear(GL_COLOR_BUFFER_BIT); //Clear the buffer

        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        float near = 1; //Near Clipping Plane
        float far = 1000; //Far Clipping Plane
        float fov = 1; //tan(fovAngle)/2.
        glFrustum(-ratio * near * fov, ratio * near * fov, -fov, fov, near, far);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();

        //Enable depth testing
        //glEnable(GL_DEPTH_TEST);

        //Set background color
        //glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

        glPushMatrix();

        glRotatef(camY, -1.0, 0.0, 0.0);
        glRotatef(camX, 0.0, 1.0, 0.0);

        //glTranslatef(0,0,-10);

        glBegin(GL_QUADS);
            //glColor3f(1.0, 0.0, 0.0);
            glVertex3f(-1.0, -1.0, -10.0);
            //glColor3f(1.0, 0.0, 1.0);
            glVertex3f(-1.0, 1.0, -10.0);
            //glColor3f(1.0, 1.0, 1.0);
            glVertex3f(1.0, 1.0, -10.0);
            //glColor3f(1.0, 1.0, 0.0);
            glVertex3f(1.0, -1.0, -10.0);
        glEnd();

        glBegin(GL_QUADS);
            glColor3f(1.0, 0.0, 0.0);
            glVertex3f(-1.0, -1.0, 10.0);
            glColor3f(1.0, 0.0, 1.0);
            glVertex3f(-1.0, 1.0, 10.0);
            glColor3f(1.0, 1.0, 1.0);
            glVertex3f(1.0, 1.0, 10.0);
            glColor3f(1.0, 1.0, 0.0);
            glVertex3f(1.0, -1.0, 10.0);
        glEnd();

        glPopMatrix();

        glfwSwapBuffers(window); //Swap buffers

        glfwPollEvents(); //Poll events
    }
    Print("Window close requested");
    glfwDestroyWindow(window); //Close the window
    Print("Deinitializing");
    glfwTerminate(); //Deinitialize
    exit(EXIT_SUCCESS); //End the program
}

build.bat:

g++ -c -v -Iinclude src/Main.cpp 2>logs/build.txt
g++ -v -o bin/main Main.o -Llib -lglfw3dll -lopengl32 -lgdi32 -lDevIL -lILU -lILUT 2>logs/link.txt
del Main.o
pause

Here is the log from line one of the batch file:

Using built-in specs.
COLLECT_GCC=g++
Target: mingw32
Configured with: ../gcc-4.8.1/configure --prefix=/mingw --host=mingw32 --build=mingw32 --without-pic --enable-shared --enable-static --with-gnu-ld --enable-lto --enable-libssp --disable-multilib --enable-languages=c,c++,fortran,objc,obj-c++,ada --disable-sjlj-exceptions --with-dwarf2 --disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-runtime-libs --with-gmp=/usr/src/pkg/gmp-5.1.2-1-mingw32-src/bld --with-mpc=/usr/src/pkg/mpc-1.0.1-1-mingw32-src/bld --with-mpfr= --with-system-zlib --with-gnu-as --enable-decimal-float=yes --enable-libgomp --enable-threads --with-libiconv-prefix=/mingw32 --with-libintl-prefix=/mingw --disable-bootstrap LDFLAGS=-s CFLAGS=-D_USE_32BIT_TIME_T
Thread model: win32
gcc version 4.8.1 (GCC) 
COLLECT_GCC_OPTIONS='-c' '-v' '-I' 'include' '-shared-libgcc' '-mtune=generic' '-march=pentiumpro'
 c:/mingw/bin/../libexec/gcc/mingw32/4.8.1/cc1plus.exe -quiet -v -I include -iprefix c:\mingw\bin\../lib/gcc/mingw32/4.8.1/ src/Main.cpp -quiet -dumpbase Main.cpp -mtune=generic -march=pentiumpro -auxbase Main -version -o C:\Users\MyUsername\AppData\Local\Temp\cccPMwk6.s
GNU C++ (GCC) version 4.8.1 (mingw32)
    compiled by GNU C version 4.8.1, GMP version 5.1.2, MPFR version 3.1.2, MPC version 1.0.1
warning: MPC header version 1.0.1 differs from library version 1.0.2.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/include/c++"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/include/c++/mingw32"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/include/c++/backward"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/../../../../include"
ignoring duplicate directory "/mingw/include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/include-fixed"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/../../../../mingw32/include"
ignoring duplicate directory "/mingw/include"
#include "..." search starts here:
#include <...> search starts here:
 include
 c:\mingw\bin\../lib/gcc/mingw32/4.8.1/include/c++
 c:\mingw\bin\../lib/gcc/mingw32/4.8.1/include/c++/mingw32
 c:\mingw\bin\../lib/gcc/mingw32/4.8.1/include/c++/backward
 c:\mingw\bin\../lib/gcc/mingw32/4.8.1/include
 c:\mingw\bin\../lib/gcc/mingw32/4.8.1/../../../../include
 c:\mingw\bin\../lib/gcc/mingw32/4.8.1/include-fixed
 c:\mingw\bin\../lib/gcc/mingw32/4.8.1/../../../../mingw32/include
End of search list.
GNU C++ (GCC) version 4.8.1 (mingw32)
    compiled by GNU C version 4.8.1, GMP version 5.1.2, MPFR version 3.1.2, MPC version 1.0.1
warning: MPC header version 1.0.1 differs from library version 1.0.2.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 1ebc2a6f92fbd3aadc367a20a63fdf9f
src/Main.cpp: In function 'int main()':
src/Main.cpp:95:14: error: expected unqualified-id before '=' token
   float near = 1; //Near Clipping Plane
              ^
src/Main.cpp:96:13: error: expected unqualified-id before '=' token
   float far = 1000; //Far Clipping Plane
             ^
src/Main.cpp:98:29: error: invalid type argument of unary '*' (have 'float')
   glFrustum(-ratio * near * fov, ratio * near * fov, -fov, fov, near, far);
                             ^
src/Main.cpp:98:49: error: invalid type argument of unary '*' (have 'float')
   glFrustum(-ratio * near * fov, ratio * near * fov, -fov, fov, near, far);
                                                 ^
src/Main.cpp:98:69: error: expected primary-expression before ',' token
   glFrustum(-ratio * near * fov, ratio * near * fov, -fov, fov, near, far);
                                                                     ^
src/Main.cpp:98:74: error: expected primary-expression before ')' token
   glFrustum(-ratio * near * fov, ratio * near * fov, -fov, fov, near, far);
                                                                          ^

Sorry for just dumping everything, but I don't know what else to do. I don't see why the IL includes would cause syntax errors in syntactically correct code.

Anyone know what's going wrong?


Solution

  • As it turns out, the issue was being caused by the names of the variables, which I realized when I noticed that 'fov' was not affected. Changing 'near' and 'far' to 'near_plane' and 'far_plane' (along with all references) fixed the issue.

    Out of interest, what do 'near' and 'far' define in DevIL?