我遇到的问题是,当我绘制文本并调用" callGl()"来自InitGl类的方法,它不会在屏幕上绘制任何内容,如果我不调用它并绘制,例如,文本" play"在屏幕上,它总是显示某种"背景"与我放的颜色相同(例如color.white)。我做错了什么?
public class InitGl {
public void InittGl(int Width, int Height) {
glEnable(GL_TEXTURE_2D);
glShadeModel(GL_SMOOTH);
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
glClearDepth(1);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glViewport(0,0,Width, Height);
glMatrixMode(GL_MODELVIEW);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, Width, Height, 0, 1, -1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
public void callGl() {
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
glClearDepth(1.0f);
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
} //This is for the render thing
}
public class Menu {
Words p = new Words();
public void setWords() {
p.setWords("Comic Sans", 24, false);
}
public void Update() {
p.renderWord("PLAY", 10, 20);
}
}
public class Screen {
private InitGl in = new InitGl();
private Menu m;
private int numNull = 0; //Just an example
public Screen () {
m = new Menu();
}
public void Menu() {
if (numNull == 0) {
in.InittGl(800, 600); //It gets the screen size
m.setWords();
numNull = 1;
}
m.Update();
}
public void Render() {
in.callGL();
m.Render(in);
}
}
public class Screen {
private InitGl in = new InitGl();
private Menu m;
private int numNull = 0; //Just an example
public Screen () {
m = new Menu();
}
public void Menu() {
if (numNull == 0) {
in.InittGl(800, 600); //It gets the screen size
m.setWords();
numNull = 1;
}
m.Update();
}
public void Render() {
m.Render(in);
}
}
public class Words {
public TrueTypeFont font;
public Font awtFont;
public void setWords(String type, int size, boolean antiAliazing) {
awtFont = new Font(type, Font.BOLD, size);
font = new TrueTypeFont(awtFont, antiAliazing);
}
public void renderWord(String phrase, int x, int y) {
font.drawString(x, y, phrase, Color.white);
}
}
答案 0 :(得分:1)
首先调用callGl()
然后绘制你的框架......因为如果你在使用glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
之前绘制任何内容,那么你会得到一个黑屏:)
尝试将m.Update();
置于渲染方法....因为你需要在每一帧中渲染你的文字......不只是一次;)
public void Render() {
in.callGL(); // <-------- prepare new frame
m.Update() // <-------- draw the text in the new frame
m.Render(in);
}
m.Render(in);
是什么意思?我无法在菜单类