我正在做一个Gr 12项目。基本思想是渲染可以通过swing GUI更改的地图纹理 我坚持使用一个支持JFrame的显示器进行渲染。 没有任何东西出现,我无法弄明白。香港专业教育学院改变了背景颜色和渲染颜色。下面是一些代码:
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);
}
}
}
有许多代码,所以我非常希望问题存在于那里。我试着格式化一下。这将解释未使用的对象/引用ext。这是唯一与LWJGL相关的代码。 DisplayWindow作为新的Runnable线程运行 这就是该程序目前的样子: grr http://img839.imageshack.us/img839/6697/grrf.jpg
为什么显示屏上没有显示?
答案 0 :(得分:2)
固定。它归结为非常基本的缺乏理解。我试图用
渲染一个彩色矩形glColor3f(1,1,1);
而
GL_TEXTURE_2D
已启用。看来好像
glDisable(GL11.GL_TEXTURE_2D );
必须在彩色形状渲染之前调用。假设
glEnable(GL11.GL_TEXTURE_2D );
已被召唤。
答案 1 :(得分:0)
你的gl - 物体来自哪里?尝试预先添加GL11。在所有gl函数调用之前,窗口初始化看起来很好。你报告了什么错误吗?