페이드 인하거나 페이드 아웃하도록 프로그래밍 된 쿼드로 텍스처를 매핑하려고합니다. 코드는 오류없이 실행되지만 텍스처는로드되지 않습니다. 내가 얻는 것은 모두 흰색 인 쿼드입니다. 저는 Java와 OpenGL을 처음 접했고 왜 작동하지 않는지 이해하지 못합니다. 나는 여러 가지 방법으로 그것을 변경하려고했지만 여전히 무엇이 잘못되었는지를 알 수 없다. 도와주세요, 소스는 다음과 같습니다OpenGL에서 사변형에 바인딩 된 텍스처의 불투명도를 어떻게 변경합니까?
package smooth_transitions;
import static org.lwjgl.opengl.GL11.*;
import org.lwjgl.opengl.*;
import org.lwjgl.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
public class SmoothTransitions {
private static enum State{
STUDIO, INTRO, FADING, MAIN;
}
private State state = State.INTRO;
private Texture background;
private Texture menu;
private Texture intro;
public static final int WIDTH = 640;
public static final int HEIGHT = 480;
public SmoothTransitions(){
try{
Display.setDisplayMode(new DisplayMode(640,480));
Display.setTitle("Hello, LWJGL!");
Display.setVSyncEnabled(true);
Display.create();
} catch (LWJGLException e){
System.err.println("Creation of the display failed.");
e.printStackTrace();
System.exit(1);
}
try {
Texture texture = TextureLoader.getTexture("PNG", new FileInputStream(new File("res/football.png")));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//Initialisation code OpenGL
glMatrixMode(GL_PROJECTION); //Just do it lol
glLoadIdentity();
glOrtho(0, 640, 480, 0, 1, -1); //This time it sets the origin to the upper-right whilst -1,-1 is bottom left
glMatrixMode(GL_MODELVIEW);
glEnable(GL_BLEND); //Enables trancluency
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
float fade = 0f; //Amount of fade.
while (!Display.isCloseRequested()){ //While close is NOT requested.
//Render
glClear(GL_COLOR_BUFFER_BIT); //Just buffers it I guess? Makes it perform better maybe.
switch (state){
case FADING:
background = loadTexture("football");
if (fade < 90){ // If opacity is under 100%, increment by 1.5
fade += 2.5f;
} else {
fade = 0;
background.bind();
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2i(WIDTH/2 - 150, 0);
glTexCoord2f(1, 0);
glVertex2i(WIDTH/2 + 150, 0);
glTexCoord2f(1, 1);
glVertex2i(WIDTH/2 + 150, HEIGHT);
glTexCoord2f(0, 1);
glVertex2i(WIDTH/2 - 150, HEIGHT);
glEnd();
state = State.MAIN;
System.out.println("State changed: " + state);
break;
}
background = loadTexture("football");
background.bind();
glColor4f(1.0f, 1.0f, 1.0f, (float) Math.sin(Math.toRadians(fade)));
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2i(WIDTH/2 - 150, 0);
glTexCoord2f(1, 0);
glVertex2i(WIDTH/2 + 150, 0);
glTexCoord2f(1, 1);
glVertex2i(WIDTH/2 + 150, HEIGHT);
glTexCoord2f(0, 1);
glVertex2i(WIDTH/2 - 150, HEIGHT);
glEnd();
break;
case INTRO:
break;
case MAIN:
background.bind();
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2i(WIDTH/2 - 150, 0);
glTexCoord2f(1, 0);
glVertex2i(WIDTH/2 + 150, 0);
glTexCoord2f(1, 1);
glVertex2i(WIDTH/2 + 150, HEIGHT);
glTexCoord2f(0, 1);
glVertex2i(WIDTH/2 - 150, HEIGHT);
glEnd();
break;
}
while (Keyboard.next()){
if (Keyboard.isKeyDown(Keyboard.KEY_RETURN)){
switch (state){
case FADING:
fade = 0;
state = State.MAIN;
System.out.println("State changed: " + state);
break;
case INTRO:
state = State.FADING;
System.out.println("State changed: " + state);
break;
case MAIN:
state = State.INTRO;
System.out.println("State changed: " + state);
break;
}
}
}
Display.update(); //This updates the screen.
Display.sync(60); //This sets the framerate.
}
Display.destroy(); //This closes the window.
}
private Texture loadTexture(String key){
try {
return TextureLoader.getTexture("PNG", new FileInputStream(new File("res/" + key + ".png")));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
public static void main(String[] args) {
new SmoothTransitions();
}
}
걱정하지 마세요, 그것을 고정 :)하지만 누군가가 그것을 읽는 경우, 그들은 어떤 행렬이며,이 모든 또는 적어도에 나를 직접 무엇을 말해 줄래 초보자가 자신이 무엇인지 알 수있는 장소? 감사. glMatrixMode (GL_PROJECTION); // 그냥해라. glLoadIdentity(); glOrtho (0, 640, 480, 0, 1, -1); // 이번에는 원점을 -1, -1을 왼쪽 아래로 설정합니다. glMatrixMode (GL_MODELVIEW); glEnable (GL_BLEND); // trancluency를 활성화합니다. glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); –
1) 주석에 코드를 붙여 넣지 마십시오. 작동하지 않습니다. 2) 그것을 풀면 다른 사람들이 참조 할 수 있도록 자신의 질문에 답하십시오. –