VBO与纹理LWJGL [英] VBO with texture in LWJGL

查看:338
本文介绍了VBO与纹理LWJGL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何附上一个纹理到VBO?

How do I attach a texture to a VBO?

我有它正与colorBuffer,现在我要实现的纹理。 这是我的绘制方法:

I had it working with a colorBuffer and now i want to implement a texture. This is my draw method:

Color.white.bind();
glBindTexture(GL_TEXTURE_2D, texture.getTextureID());

glBindBuffer(GL_ARRAY_BUFFER, vboVertexHandle);
glBufferData(GL_ARRAY_BUFFER, vertexData, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, vboVertexHandle);
glBufferData(GL_ARRAY_BUFFER, textureData, GL_STATIC_DRAW);
glVertexPointer(vertexSize, GL_FLOAT, 0, 0L);




glEnableClientState(GL_VERTEX_ARRAY);
glTexCoordPointer(3, GL_FLOAT, 0, 0);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glDrawArrays(GL_QUADS, 0, amountOfVertices);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);

这根本不​​显示任何内容。纹理正确laoded,我得到它的直接模式下工作。 什么我必须做的,使其与驻维也纳各组织工作?

That doesn't display anything at all. the texture is correctly laoded and I got it working with the immediate mode. What do I have to do to make it work with VBOs ?

推荐答案

貌似VBO的纹理坐标是不是在设置texCoordPointer约束。改变你的命令的顺序应该工作。同时要覆盖的顶点,在你的单身VBO您TEXCOORD数据。最简单的解决办法就是让每一个两个独立的维也纳各组织。

Looks like the VBO for the texture coordinates is not bound while setting the texCoordPointer. Changing the order of your commands should work. Also you are overriding the vertex with your texCoord data in your single VBO. Easiest solutions would be to have two separate VBOs for each.

glBindTexture(GL_TEXTURE_2D, texture.getTextureID());
// vertices
glBindBuffer(GL_ARRAY_BUFFER, vboVertexHandle);
glBufferData(GL_ARRAY_BUFFER, vertexData, GL_STATIC_DRAW);
glVertexPointer(vertexSize, GL_FLOAT, 0, 0L);
// texCoords
glBindBuffer(GL_ARRAY_BUFFER, vboTexCoordHandle);
glBufferData(GL_ARRAY_BUFFER, textureData, GL_STATIC_DRAW);
glTexCoordPointer(3, GL_FLOAT, 0, 0);
// unbind VBO
glBindBuffer(GL_ARRAY_BUFFER, 0);

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glDrawArrays(GL_QUADS, 0, amountOfVertices);

glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);

注:通常你不想通过调用glBufferData一次以上VBO创建新的维也纳组织每一帧

Note: usually you don't want to create new VBOs each frame by calling glBufferData more than once per VBO.

这篇关于VBO与纹理LWJGL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆