0

我正在尝试使用 JOGL 渲染一个简单的 jpg 图像。但是,我不确定如何包装像素数组数据以便 glDrawPixels 接受它。这是我到目前为止的相关部分:

//In Main() Method
private static float[] pixels = {
    0.f, 1.f, 0.f,
    1.f, 0.f, 1.f,
    0.f, 1.f, 0.f
};

//In Render() Method
gl.glRasterPos3f(12.0f, 12.0f, 5.0f);
gl.glDrawPixels(3, 3, GL.GL_RGBA, GL.GL_FLOAT, pixels);

Eclipse 告诉我 glDrawPixels 接受缓冲区而不是浮点数组,所以我想我需要先将像素放入缓冲区并指定缓冲区,但我不确定如何执行此操作或使用哪个缓冲区。我需要使用 glPixelStore*() 吗?任何帮助将非常感激。谢谢!

- 编辑 -

我试图将信息放入 FloatBuffer 并且该方法接受了它,但屏幕上没有显示任何内容。我是正确地将数组包装到缓冲区中,还是我调用 gl 函数的问题?这是更新的代码:

private static float[] pixels = {
    0.f, 1.f, 0.f,
    1.f, 0.f, 1.f,
    0.f, 1.f, 0.f
};

static FloatBuffer buf; 

//In Main() Method
buf.wrap(pixels);

//In Render() method
gl.glRasterPos3f(0.0f, 0.0f, 0.0f);
gl.glPixelZoom(50.0f, 50.0f);
gl.glDrawPixels(3, 3, GL.GL_RGBA, GL.GL_FLOAT, buf);

When I run the program, it just shows a black screen.

4

1 回答 1

0

The buffer Eclipse is talking about is nothing OpenGL specific (per se). The OpenGL functions expect a pointer to the memory locations where to find the data. Java doesn't have pointers, so you need a Java buffer object (not to confuse with a OpenGL buffer object) that provides some way to extract a pointer that can be passed to OpenGL. For example a Java FloatBuffer. You can pass an instance of that to the OpenGL gl…Pointer functions as data parameter then.

于 2013-09-15T15:55:32.183 回答