我有一个由顶点数组绘制的 3D 立方体 -
public void init(GLAutoDrawable drawable) {
...
float[] cubeVertices = {...}; // vertex coordinates (x,y,z)
FloatBuffer tmpVerticesBuf = BufferUtil
.newFloatBuffer(cubeVertices.length);
for (int i = 0; i < cubeVertices.length; i++) {
tmpVerticesBuf.put(cubeVertices[i]);
}
tmpVerticesBuf.rewind();
gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
gl.glVertexPointer(3, GL.GL_FLOAT, 0, tmpVerticesBuf);
}
public void display(GLAutoDrawable drawable) {
...
gl.glDrawArrays(GL.GL_QUADS, 0, 24);
...
}
现在我想在这个立方体的面上设置一张纹理图片,这样它就与所有立方体面的纹理相同。到目前为止,我在init()
-
public void init(GLAutoDrawable drawable) {
...
try {
// retrieve the image .
BufferedImage image = ImageIO.read(getClass().getClassLoader()
.getResource("floor.jpg"));
DataBufferByte dbb = (DataBufferByte) image.getRaster()
.getDataBuffer();
byte[] data = dbb.getData();
ByteBuffer pixels = BufferUtil.newByteBuffer(data.length);
pixels.put(data);
pixels.flip();
} catch (GLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
m_textutureIntBuf = IntBuffer.allocate(1); // m_textutureIntBuf type IntBuffer
gl.glGenTextures(1, m_textutureIntBuf);
gl.glBindTexture(GL.GL_TEXTURE_2D, m_textutureIntBuf.get(0));
gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB, 256, 256, 0, GL.GL_RGB,
GL.GL_UNSIGNED_BYTE, m_pixels);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER,
GL.GL_LINEAR);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER,
GL.GL_NEAREST);
gl.glEnable(GL.GL_TEXTURE_2D);
}
gl.glTexCoordPointer()
gl.glEnableClientState()
为了得到我之前提到的关于纹理的内容,我现在必须做什么?