将C ++ OpenGl转换为Java(LWJGL),glBufferData(); [英] Converting C++ OpenGl to Java(LWJGL), glBufferData();

查看:111
本文介绍了将C ++ OpenGl转换为Java(LWJGL),glBufferData();的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在弄乱LWJGL,试图创建一个.obj解析器,该解析器会将从Blender导出的文件转换为OpenGL渲染代码.我遵循了与我正在做的事情相似的教程,但是它是用C ++编写的,我很难理解.我已经设法使所有的东西都与解析器一起工作(我认为),但是当需要实际渲染到模型时,我很难创建与C ++代码等效的Java.本教程使用以下代码行:

I've been messing around with LWJGL trying to create a .obj parser that will convert files exported from blender into OpenGL render code. I followed a tutorial similar to what i was doing, but it was written in c++, which i can hardly comprehend. I've managed to get everything working with the parser(I think) but when the time comes to actually render to model, i'm having a hard time creating a java equivalent of the c++ code. The tutorial uses this line of code:

glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(glm::vec3), &vertices[0], GL_STATIC_DRAW);

然后(显然)它绘制数组.我很确定我需要将Vecotor3f的列表(顶点)转换为FloatBuffer,并且我不需要第二个参数(因为java将处理大小).但是,我不知道如何执行此操作,我仍在寻找Java的出路,并且以前从未使用过此类.

Then (obviously) it draws the array. I'm pretty sure i need to convert Vecotor3f's from my list(The vertices) to a FloatBuffer, and i don;t need the second parameter(Because java will handle the size). I however, have no clue how to do this, i'm still finding my way around java, and have never used this class before.

推荐答案

FloatBuffer vertexData = BufferUtils.createFloatBuffer(amountOfVertices * vertexSize);
vertexData.put(vertices);
vertexData.flip();

glBufferData(GL_ARRAY_BUFFER, vertexData, GL_STATIC_DRAW);

是等效的Java代码,其中vertices是包含顶点数据的浮点数组,vertexSize是每个顶点的浮点数,而amountOfVertices是不言而喻的.如果需要,可以将amountOfVertices * vertexSize切换为vertices.length.

Is the equivalent java code, where vertices is a float array containing your vertex data, vertexSize is the number of floats per vertex and amountOfVertices is self explanatory. You could switch amountOfVertices * vertexSize with vertices.length if you want as they should be equal.

这篇关于将C ++ OpenGl转换为Java(LWJGL),glBufferData();的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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