C ++ Freeglut运行时检查失败#2-S,Visual Studio C ++

时间:2019-10-01 13:01:35

标签: c++ freeglut

C ++我正在开发游戏引擎,但是我的代码无法正常工作。 我试过了: 更改代码位置... 更改类型

这是我的代码:

...
    #include "pch.h"
    #include <iostream>
    #include "glut.h"

    #include "conio.h"
    using namespace std;

    #include<stdio.h>
    #include "map_loader.h"
    #include "models.h"
    #include "IEDX_POLYTEX.h"
    #include "FONTGER/include/fontmann.h"
    #define KEY_ESC 27 /* GLUT doesn't supply this */
    #pragma comment(lib, "GLAUX_iedx_fonts.lib")

//Void display: i dont give full code. only this part of void Display()
...
    GLuint my_texture[13] = { 0xffaec900, 0x0000ffae, 0xc9ffaec9,
        0xffaec9ff, 0xaec90000, 0x00ffaec9,
        0x000000ff, 0xaec9ffae, 0xc9000000,
        0xffaec900, 0x00000000, 0x00ffaec9 }
        ;
    glTexImage2D(GL_TEXTURE_2D, 0, 3, 16, 16, 0,
        GL_RGB8, GL_UNSIGNED_BYTE, my_texture);
    glGenTextures(34, my_texture);
    glBindTexture(GL_TEXTURE_2D, 34);
...

当我运行我的应用程序时 skiRun-Time检查失败#2-S,Visual Studio C ++

没有编译器错误等。

链接器没问题。

当应用程序崩溃且我尝试单击重试时,game.exe已停止工作...

1 个答案:

答案 0 :(得分:0)

您似乎需要阅读OpenGL简介;该代码毫无意义。

我相信导致运行时错误的特殊原因是,您正在将34个纹理名称生成到只能容纳13个的数组中。
(请仔细阅读文档。如果您听不懂,不要猜测,但请继续学习。)

请记住,OpenGL是有状态的,您必须按一定顺序执行某些操作。

正常的做事方式是

//Generate a texture name:
GLuint name = 0;
glGenTextures(1, &name);
// Bind this texture:
glBindTexture(GL_TEXTURE_2D, name);
// Now you can load the texture into OpenGL:
glTexImage2D(GL_TEXTURE_2D, 0, 3, 16, 16, 0,
             GL_RGB8, GL_UNSIGNED_BYTE, my_texture);

您对glTexImage2D的参数也似乎有疑问-它们似乎根本与您的纹理数组不符。