Android:OpenGL纹理和glDrawTexfOES问题

发布于 2024-10-01 15:31:37 字数 966 浏览 0 评论 0原文

我试图遵循我能找到的所有信息,但我没有运气找到我的纹理问题的根源,并且真的需要用手。

以下是我尝试使用 glDrawTexfOES 绘制 3 块背景的代码。这 3 块应该看起来像绿草。

public void onDrawFrame(GL10 gl) {

    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    gl.glLoadIdentity();

    gl.glFrontFace(GL10.GL_CW);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
    gl.glEnable(GL10.GL_TEXTURE_2D);

    gl.glBindTexture(GL10.GL_TEXTURE_2D, grass);

    gl.glColor4x(0x10000, 0x00000, 0x10000, 0x10000);

    ((GL11Ext) gl).glDrawTexfOES(0.0f, 0.0f, -8.0f, 32, 32);
    ((GL11Ext) gl).glDrawTexfOES(32.0f, 0.0f, -8.0f, 32, 32);
    ((GL11Ext) gl).glDrawTexfOES(64.0f, 0.0f, -8.0f, 32, 32);
}

然而,我得到的不是绿草,而是 3 个棕色方块: http://img109.imageshack.us/img109/9670/84615249.jpg

任何帮助弄清楚为什么我的纹理无法正确显示的帮助将不胜感激!

在相关说明中,对于构建简单的 2D 平铺游戏,glDrawTexfOES 是生成平铺背景的最有效方法吗?

提前致谢, 哈利

I've tried to follow all the information I could find, but I am not having any luck finding the source of my texture problems and could really use a hand.

The following is piece of code in which I'm trying to draw 3 pieces of my background using glDrawTexfOES. The 3 pieces should look like green grass.

public void onDrawFrame(GL10 gl) {

    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    gl.glLoadIdentity();

    gl.glFrontFace(GL10.GL_CW);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
    gl.glEnable(GL10.GL_TEXTURE_2D);

    gl.glBindTexture(GL10.GL_TEXTURE_2D, grass);

    gl.glColor4x(0x10000, 0x00000, 0x10000, 0x10000);

    ((GL11Ext) gl).glDrawTexfOES(0.0f, 0.0f, -8.0f, 32, 32);
    ((GL11Ext) gl).glDrawTexfOES(32.0f, 0.0f, -8.0f, 32, 32);
    ((GL11Ext) gl).glDrawTexfOES(64.0f, 0.0f, -8.0f, 32, 32);
}

Instead of green grass however, I'm getting 3 brown squares:
http://img109.imageshack.us/img109/9670/84615249.jpg

Any help in figuring out why my textures won't display correctly would be most appreciated!

On a related note, for building a simple 2D tiled game is glDrawTexfOES the most efficient method for generating the tiled background?

Thanks in advance,
Harry

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不寐倦长更 2024-10-08 15:31:38

如果你用谷歌搜索大多数 OpenGL 函数,你会得到该函数的文档,然后是示例。对于该功能,结果主要是遇到麻烦的人。

该函数可能比通常的方式使用纹理稍微快一些(我没有使用过它,所以我不知道),但简单地将纹理应用到四边形不需要扩展,并且非常便携。

您为什么不尝试一下并回复我们...可能该功能运行良好,但初始化纹理时出现了问题。使用简单的纹理四边形方法也将帮助您找到答案。

If you google most OpenGL functions you get documentation for the function, followed by examples. For that function, the results are dominated by people having trouble.

That function might be slightly faster than using textures the usual way (I haven't used it so I don't know), but simply applying a texture to a quad needs no extensions and is extremely portable.

Why don't you try that and get back to us... it could be that the function is working perfectly, but something went wrong initializing the texture. Using the uncomplicated texture-a-quad method will help you find that out as well.

爱*していゐ 2024-10-08 15:31:37

您需要定义图像到矩形的映射
您可能只是获得图像的左上角像素。

int[]crop={0,0,text_dimx,text_dimy};
((GL11) gl).glTexParameteriv(GL10.GL_TEXTURE_2D, GL11Ext.GL_TEXTURE_CROP_RECT_OES, 作物,0);

You need to define the mapping of the image to the rectangle
You are probably just getting the top left pixel of the image.

int[]crop={0,0,text_dimx,text_dimy};
((GL11) gl).glTexParameteriv(GL10.GL_TEXTURE_2D, GL11Ext.GL_TEXTURE_CROP_RECT_OES, crop,0);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文