由于某种原因,我加载的纹理不会显示/渲染。我已经获得了一个纹理,可以用几乎相同的代码在以前的项目上渲染,但由于某种原因,它不会用下面的代码渲染。我已经发布了 init() 和 createGreenFields() 方法,显示方法调用 gl.glCallList(1) 来创建字段。
public void init(GLAutoDrawable drawable) {
// Initialize object state.
glu = new GLU();
GL2 gl = drawable.getGL().getGL2();
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glDepthFunc(GL.GL_LEQUAL);
gl.glShadeModel(GL2.GL_SMOOTH);
try {
grassTex = TextureIO.newTexture(new File(grassFile), true);
grassTex.setTexParameteri(gl, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
grassTex.setTexParameteri(gl, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST);
} catch (Exception e) {
System.out.println("Error loading texture " + e);
}
gl.glClearDepth(1.0f);
createGreenFields(gl);
}
.
.
.
private void createGreenFields(GL2 gl) {
int index = gl.glGenLists(1);
gl.glNewList(index, GL2.GL_COMPILE);
gl.glBegin(GL2.GL_QUADS); // Four vertices
.
.
// do not draw the transparent parts of the texture
gl.glEnable(GL.GL_BLEND);
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
// don't show source alpha parts in the destination
// determine which areas of the polygon are to be rendered
gl.glEnable(GL2.GL_ALPHA_TEST);
gl.glAlphaFunc(GL.GL_GREATER, 0); // only render if alpha > 0
gl.glDisable(GL.GL_BLEND);
// enable texturing
//gl.glEnable(GL2.GL_TEXTURE_3D);
grassTex.enable(gl);
grassTex.bind(gl);
// replace the quad colors with the texture
gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE);
TextureCoords tc = grassTex.getImageTexCoords();
// lower right field
gl.glColor3f(0.0f, 0.3f, 0.0f); // Dark Green
gl.glTexCoord2f(tc.left(), tc.bottom());
gl.glVertex3f(-1.66f, 15.0f, 0f);
gl.glTexCoord2f(tc.right(), tc.bottom());
gl.glVertex3f(-15.0f, 15.0f, 0f);
gl.glTexCoord2f(tc.right(), tc.top());
gl.glVertex3f(-15.0f, 1.66f, 0f);
gl.glTexCoord2f(tc.left(), tc.top());
gl.glVertex3f(-1.66f, 1.66f, 0f);
.
.
public void display(GLAutoDrawable drawable) {
.
.
gl.glCallList(1); // Creates Green Fields
.
.
}