如何用DevIL编译?

时间:2016-02-10 14:16:54

标签: g++ glfw g++4.8 devil

我正在尝试为3D程序进行正确的设置,下一步是纹理加载器。我正在尝试使用DevIL,但我似乎无法使其正常工作,并且似乎没有最新的解释性文本。

首先,我要包括我的项目转储:(请记住它恰好处于这种状态,并非全部相关;还要注意&# 39; IOUtil.cpp'只定义'打印'打印到' cout'。它似乎没有相关性,所以我将其排除在外。)

项目结构:

+- 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

以下是批处理文件第一行的日志:

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);
                                                                          ^

抱歉只是倾倒一切,但我不知道还能做什么。我不明白为什么IL包含会导致语法错误的语法错误。

任何人都知道出了什么问题?

1 个答案:

答案 0 :(得分:0)

事实证明,问题是由变量的名称引起的,当我注意到'fov'没有受到影响时,我意识到了这一点。将“near”和“far”更改为“near_plane”和“far_plane”(以及所有引用)修复了此问题。

出于兴趣,Devil中“近”和“远”的定义是什么?