テクスチャの色が混ざっているのはなぜですか?どうすれば修正できますか?
これは私が描画して初期化する方法です:
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();
}
}
}
すべてがうまく描画されますが、唯一の問題は、テクスチャの色が混在していることです!
これは、アプリを実行したときのテクスチャの外観です。
これらは通常の色のテクスチャです
と