LWJGL VBO内容始终绘制在屏幕的中心(0,0,0) [英] LWJGL VBO content is always drawn to the center of the screen (0,0,0)

查看:115
本文介绍了LWJGL VBO内容始终绘制在屏幕的中心(0,0,0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始遵循有关现代OpenGL渲染的教程,并从VBO课程中更改了c ++代码以与LWJGL一起使用.我用以下代码初始化了VBO:

I started to follow a tutorial about modern OpenGL rendering and altered the c++ code from a VBO lesson to work with LWJGL. I initialized the VBO with the following code:

int vbo = GL15.glGenBuffers();
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);

缓冲区"初始化为

FloatBuffer buffer = BufferUtils.createFloatBuffer(9);

,然后通过

buffer.put(val)

我的游戏循环如下:

GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
GL20.glEnableVertexAttribArray(0);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 0, 0);
GL11.glDrawArrays(GL11.GL_POINTS, 0, 3);
GL20.glDisableVertexAttribArray(0);
Display.update();

但是我得到的只是屏幕中央的一个白点.我发现了类似的问题( VBO:未绘制数组),但是解决方案无法解决我的问题问题. 我使用的教程是 http://ogldev.atspace.co.uk/www /tutorial02/tutorial02.html http://ogldev.atspace .co.uk/www/tutorial03/tutorial03.html .当我尝试绘制GL_TRIANGLES而不是GL_POINTS时,屏幕上没有任何内容.

But all I get is a white dot in the center of the screen. I found a similar question (VBO: Array not drawn), but the solution did not fix my problem. The tutorial I used is http://ogldev.atspace.co.uk/www/tutorial02/tutorial02.html and http://ogldev.atspace.co.uk/www/tutorial03/tutorial03.html. When I try to draw GL_TRIANGLES instead of GL_POINTS, nothing is drawn onto the screen.

推荐答案

浪费时间阅读不同的教程之后,我发现我没有rewind()我的缓冲区...

After wasting hours reading different tutorials, I figured out that I did not rewind() my buffer...

GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);

GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);

VBO:未绘制阵列中所建议.

这篇关于LWJGL VBO内容始终绘制在屏幕的中心(0,0,0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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