-1

I am learning the "light.c" example described at http://www.glprogramming.com/red/chapter05.html

After successfully run the example written in C, I modified it to draw a box instead of a sphere. After that, I also translated the C code into Java using LWJGL. However, the Java version doesn't work at all.

Both the C and Java versions are pasted at https://gist.github.com/stfairy/d2aa2f48a9a5801ae72e

The screenshot below is the expected result (which is generated by the C version, but the Java version only gives a black window)

expected result

4

1 回答 1

1

将此问题发布到 LWJGL 论坛后,我得到了回复,现在我有一个修复程序。

我想这是因为我不明白它是如何nio.Buffer工作的。将 写入 后valuesbuffer我们还需要通过调用 来重置光标位置rewind(),否则对材质和灯光位置使用零。下面列出的最终代码。

private FloatBuffer floatBuffer(float... values) {
    FloatBuffer buffer = BufferUtils.createFloatBuffer(Math.max(4, values.length));
    buffer.put(values);
    return (FloatBuffer) buffer.rewind();
}
于 2013-10-10T01:36:04.237 回答