I'm doing a Gr 12 Project. the basic idea is to render a map texture that can be changed via the swing GUI.
I'm stuck at rendering using a Display that's .parented to a JFrame.
Nothing is showing up and i cant figure it out. ive changed the backround color and the rendering color. heres some of the code:
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);
}
}
}
There is allot of code so I dearly hope the problem is in there. I tried to format it a bit. that will explain unused objects/references ext. this is the only code related to LWJGL. DisplayWindow is run as a new Runnable thread.
This is what the program looks like at the moment:
grr http://img839.imageshack.us/img839/6697/grrf.jpg
Why is nothing showing in the display?