为什么纹理的颜色是混合的?我该如何解决?
这就是我绘制和初始化的方式:
private void initGL_3D() {
int width = Display.getWidth();
int height = Display.getHeight();
glLoadIdentity(); // Reset The Projection Matrix
GLU.gluPerspective(45.0f, ((float) width / (float) height), 0.1f, 100.0f); // Calculate The Aspect Ratio Of The Window
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix
glShadeModel(GL_SMOOTH); // Enables Smooth Shading
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Test To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
}
private void initGL_2D() {
int width = Display.getWidth();
int height = Display.getHeight();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0f, width, height, 0.0f, 1, -1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDisable(GL_DEPTH_TEST);
// Enable transparency
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
private void renderGL() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
int width = Display.getWidth();
int height = Display.getHeight();
glEnable(GL_TEXTURE_2D);
glViewport(0, 0, width, height); // Reset The Current Viewport\
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
if (game){
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background
initGL_3D();
renderGL_3D();
}
initGL_2D();
renderGL_2D();
}
private void renderGL_3D() {
glLoadIdentity();
glTranslatef(0, 0f, -3f);
glRotatef(rotationX, 1.0f,0.0f,0.0f);
glRotatef(rotationY/4, 0.0f,1.0f,0.0f);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture1.getTextureID());
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, texture2.getTextureID());
glBegin(GL_TRIANGLES);
glMultiTexCoord2f(GL_TEXTURE0, 0, 0);
glVertex3f(0, 0, 0);
glMultiTexCoord2f(GL_TEXTURE0, 1, 0);
glVertex3f(1, 0, 0);
glMultiTexCoord2f(GL_TEXTURE0, 0, 1);
glVertex3f(0, 1, 0);
glMultiTexCoord2f(GL_TEXTURE1, 1, 1);
glVertex3f(1, 1, 0);
glMultiTexCoord2f(GL_TEXTURE1, 1, 0);
glVertex3f(1, 0, 0);
glMultiTexCoord2f(GL_TEXTURE1, 0, 1);
glVertex3f(0, 1, 0);
glEnd();
}
private void renderGL_2D() {
if (mainMenu) {
gui.setBackground(0);
glLoadIdentity();
for (Button button : gui.buttons) {
float posX;
float posY;
if (button.posX == "center") {
posX = Display.getWidth()/2-button.width/2;
} else {
posX = Integer.parseInt(button.posX);
}
if (button.posY == "center") {
posY = Display.getHeight()/2-button.height/2;
} else {
posY = Integer.parseInt(button.posY);
}
if(guiMouseX > posX && guiMouseY > posY && guiMouseX < posX + button.width && guiMouseY < posY + button.height){
button.textureOver.bind();
button.mouseOver.run();
if (Mouse.isButtonDown(0)) {
button.mouseDown.run();
}
} else {
button.texture.bind();
}
float imageWidth = button.texture.getImageWidth();
float textureWidth = button.width/imageWidth;
float imageHeight = button.texture.getImageHeight();
float textureHeight = button.height/imageHeight;
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2f(posX, posY);
glTexCoord2f(textureWidth, 0);
glVertex2f(posX + button.width, posY);
glTexCoord2f(textureWidth, textureHeight);
glVertex2f(posX + button.width, posY + button.height);
glTexCoord2f(0, textureHeight);
glVertex2f(posX, posY + button.height);
glEnd();
}
}
}
一切都画得很好,但唯一的问题是纹理颜色混合在一起!
这是我运行应用程序时纹理的外观
这些是具有正常颜色的纹理
和