1

我有一些代码试图在我的笔记本电脑上运行,但它不断给出“FALLBACK”错误。我不知道它是什么,但它很烦人。它应该只打印“Hello world!”,但它会打印两次并稍微改变颜色。

相同的代码在我的 PC 上完美运行。

我已经搜索了很长时间来解决这个问题,但找不到任何东西。我希望这里的一些人可以帮助我?

这是我的代码:

// Template, major revision 3

#include "string.h"
#include "surface.h"
#include "stdlib.h"
#include "template.h"
#include "game.h"

using namespace Tmpl8;

void Game::Init()
{
    // put your initialization code here; will be executed once
}

void Game::Tick( float a_DT )
{
    m_Screen->Clear( 0 );
    m_Screen->Print( "hello world", 2, 2, 0xffffff );
    m_Screen->Line( 2, 10, 66, 10, 0xffffff );
}

提前致谢!:-)

编辑:

它在这一行给出了一个错误:

glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, SCRWIDTH, SCRHEIGHT, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL );

也许这会有所帮助?

4

3 回答 3

4

查看OpenGL 论坛上的这篇文章并看到您正在使用 OpenGL,我可能会有一个想法。您说该代码在您的计算机上运行良好,但在您的笔记本电脑上却不行。那里有可能的硬件(不同的视频卡)和软件(不同的 OpenGL 版本/支持)。

可能发生的情况是您的笔记本不支持您想要从 OpenGL 使用的功能。此外,您正在创建一个没有数据的纹理(最后一个参数为 NULL),这可能会给您带来诸如缓冲区溢出之类的错误。

编辑:

你可以看看GLEW。它有一个名为“glewinfo”的工具,可以查找硬件/驱动程序上可用的所有功能。它在可执行文件的相同路径上生成一个同名文件。对于两个纹理的力量,寻找 GL_ARB_texture_non_power_of_two。

编辑2:

正如您在评论中所说,如果没有 GL_ARB_texture_non_power_of_two 扩展,并且纹理的大小为 640x480,glTexture 会给您一个错误,并且所有依赖它的代码都可能会失败。要修复它,您必须将图像的尺寸拉伸到二的下一个幂。在这种情况下,它将变为 1024x512。请记住,您提供给 glTexture 的数据必须具有这些维度。

于 2011-02-09T14:45:28.187 回答
0

Seeing that the error comes from the line:

glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, SCRWIDTH, SCRHEIGHT, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL );

Here are the reasons why that function could return GL_INVALID_VALUE. Since I can't check it for sure, you'll have to go through this list and make sure which one of them caused this issue.

GL_INVALID_VALUE is generated if level is less than 0.

GL_INVALID_VALUE may be generated if level is greater than log 2 ⁡ max , where max is the returned value of GL_MAX_TEXTURE_SIZE.

GL_INVALID_VALUE is generated if internalFormat is not 1, 2, 3, 4, or one of the accepted resolution and format symbolic constants.

GL_INVALID_VALUE is generated if width or height is less than 0 or greater than 2 + GL_MAX_TEXTURE_SIZE.

GL_INVALID_VALUE is generated if non-power-of-two textures are not supported and the width or height cannot be represented as 2 k + 2 ⁡ border for some integer value of k.

GL_INVALID_VALUE is generated if border is not 0 or 1.

EDIT: I believe it could be the non-power-of-two texture size that's causing the problem. Rounding your texture size to the nearest power-of-two should probably fix the issue.

EDIT2: To test which of these is causing an issue, let's start with the most common issue; trying to create a texture of non-power-of-two size. Create an image of size 256x256 and call this function with 256 for width and height. If the function still fails I would try putting the level to 0 (keeping the power-of-two size still in place).

BUT DANG you don't have data for your image? It's set as NULL. You need to load the image data into memory and pass it to the function to create the texture. And you aren't doing that. Read how to load images from a file or how to render to texture, whichever is relevant to you.

于 2011-02-22T14:40:22.540 回答
0

这是为了给你一个更好的答案作为一个新的帖子。首先,您需要此辅助函数将 bmp 文件加载到内存中。

unsigned int LoadTex(string Image)
{
    unsigned int Texture;

                FILE* img = NULL;
                img = fopen(Image.c_str(),"rb");

    unsigned long bWidth = 0;   
    unsigned long bHeight = 0;  
    DWORD size = 0; 

    fseek(img,18,SEEK_SET);
    fread(&bWidth,4,1,img);
    fread(&bHeight,4,1,img);
    fseek(img,0,SEEK_END);
    size = ftell(img.file) - 54;

    unsigned char *data = (unsigned char*)malloc(size);

    fseek(img,54,SEEK_SET); // image data
    fread(data,size,1,img);

    fclose(img);

    glGenTextures(1, &Texture);
    glBindTexture(GL_TEXTURE_2D, Texture);
    gluBuild2DMipmaps(GL_TEXTURE_2D, 3, bWidth, bHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, data);

    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

    if (data)
        free(data);

    return Texture;
}

礼貌:由 b0x 在 Game Deception 中发布

然后你需要在你的代码中同样调用它:

unsigned int texture = LoadTex("example_tex.bmp");
于 2011-02-22T16:47:15.000 回答