我正在做一个 12 年级的项目。基本思想是渲染可以通过摇摆 GUI 更改的地图纹理。
我坚持使用以 .parented 为 JFrame 的 Display 进行渲染。什么都没有出现,我无法弄清楚。我改变了背景颜色和渲染颜色。继承人的一些代码:
public class DisplayWindow extends JFrame{
public Canvas canvas = new Canvas();
private JPanel westPanel=new JPanel();
private List animalArr;
private List animalOptionsBoxArr;
public JLabel optionsLabel=new JLabel();
public JToggleButton animalIOToggle = new JToggleButton();
public JTextArea animalIOText = new JTextArea();
List renderableEntities= new ArrayList();
//states modified by logic class that handle all swing listners
private boolean resizePending=false;
private boolean exitPending=false;
DisplayWindow(List animalArr)
{
super();
this.animalArr=animalArr; //created from db in logic class
}
public void run()
{
startDisplay();
}
public void startDisplay()
{
//Init GUI
setupFrame(); //setup main Jframe
setupMainPanels(); //setup main panels within JFrames borderLayout)
setupContentPanels(); //setup the content panels within the main panel
canvas.setSize(getDisplayWidth(), getDisplayHeight());
canvas.setFocusable(true);
canvas.setIgnoreRepaint(true);
this.add(canvas,BorderLayout.CENTER);
this.setVisible(true);
//Display Setup
try
{
Display.setResizable(true);
Display.setParent(canvas);
Display.sync(60);
Display.create();
}
catch(LWJGLException ex)
{
Error.fatalError("Failed to Initialise Park Display",ex);
}
//OpenGL INIT
glClearColor(0.0f,0.0f,0.0f,0.0f); //black backround
glEnable(GL11.GL_TEXTURE_2D);
glEnable(GL11.GL_BLEND);
glBlendFunc(GL11.GL_SRC_ALPHA,GL11.GL_ONE_MINUS_SRC_ALPHA);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,getDisplayWidth(),0,getDisplayHeight(),1,-1);
glMatrixMode(GL_MODELVIEW);
//Render Loop
while(!isExitPending())
{
glClear(GL_COLOR_BUFFER_BIT);
render();
checkResizeDisplay();
Display.update();
}
cleanUp();
}
public void render()
{
//test Render
glColor3f(1,1,1); //white render color
glRectf(100,100,400,400);
glBegin(GL_POINTS); //point at 5 above mouse location
glVertex2d(Mouse.getX(),Mouse.getY()+5 );
glEnd();
}
public void checkResizeDisplay() //is this even neccisary?
{
if(resizePending==true)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,Display.getWidth(),0,Display.getHeight(),1,-1);
glMatrixMode(GL_MODELVIEW);
}
}
}
有很多代码,所以我非常希望问题出在那儿。我试着格式化了一下。这将解释未使用的对象/引用分机。这是与 LWJGL 相关的唯一代码。DisplayWindow 作为新的 Runnable 线程运行。
这是程序目前的样子:
grr http://img839.imageshack.us/img839/6697/grrf.jpg
为什么显示器上什么都没有显示?