Hi
Thanks for your reply.
So, I thought I'd try using AWTGLCanvas to get a working example, which could maybe added to your samples folder.
The code below consists of AWTGLCanvas_Example which is the main JFrame.
MyAWTGLCanvas extends AWTGLCanvas, which is placed on the frame.
When I run the code I get a black window and don't see the quad. Does anyone know why? When I place breakpoints in initGL() and paintGL() I discover that they are not being called.
Note the call:
mCanvas.start();
after all of the initialisation, otherwise an exception is thrown that the parent must be visible before Display is called.
Note also the commented out code:
// init OpenGL here
//LWJGLRenderer renderer = new LWJGLRenderer();
//newDim = newCanvasSize.getAndSet(null);
//GL11.glViewport(0, 0, newDim.width, newDim.height);
//renderer.syncViewportSize();
which are referred to in the example:
http://lwjgl.org/wiki/index.php?title=Using_a_Resizeable_AWT_Frame_with_LWJGLbut not defined.
PS. I used the QuadExample code as the basis for choosing something to render. Also, so that there is the current example of QuadExample that runs in its own window and this example can compare the differences regarding setup.
Thanks
Graham
=====================
package my_lwjgl;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Canvas;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.AWTGLCanvas;
import org.lwjgl.opengl.Display;
import org.lwjgl.util.Dimension;
public class AWTGLCanvas_Example extends JFrame
{
private JPanel contentPane;
private MyAWTGLCanvas mCanvas;
/**
* Create the frame.
*/
public AWTGLCanvas_Example()
{
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
try
{
mCanvas = new MyAWTGLCanvas(this);
}
catch (LWJGLException e)
{
e.printStackTrace();
}
contentPane.add(mCanvas, BorderLayout.CENTER);
this.setVisible(true);
mCanvas.start();
}
/**
* Launch the application.
*/
public static void main(String[] args)
{
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
AWTGLCanvas_Example frame = new AWTGLCanvas_Example();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
} // class AWTGLCanvas_Example
================
package my_lwjgl;
// lwjgl
import javax.swing.JFrame;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.AWTGLCanvas;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.Dimension;
public class MyAWTGLCanvas extends AWTGLCanvas
{
protected JFrame mParent;
public MyAWTGLCanvas(JFrame parent) throws LWJGLException
{
super();
mParent = parent;
}
public void start()
{
try
{
Display.setDisplayMode(new DisplayMode(800,600));
Display.setParent(this);
Display.setVSyncEnabled(true);
Display.create();
}
catch (LWJGLException e)
{
e.printStackTrace();
System.exit(0);
}
// init OpenGL here
//LWJGLRenderer renderer = new LWJGLRenderer();
Dimension newDim = null;
while (!Display.isCloseRequested())
{
//newDim = newCanvasSize.getAndSet(null);
if (newDim != null)
{
//GL11.glViewport(0, 0, newDim.width, newDim.height);
//renderer.syncViewportSize();
}
// render OpenGL here
Display.update();
}
Display.destroy();
}
// Override this to do initialising of the context. It will be called once from paint(), immediately after the context is created and made current.
public void initGL()
{
// init OpenGL
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0, 800, 600, 0, 1, -1);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
}
// Override this to do painting
protected void paintGL()
{
// Clear the screen and depth buffer
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
// set the color of the quad (R,G,B,A)
GL11.glColor3f(0.5f,0.5f,1.0f);
// draw quad
GL11.glBegin(GL11.GL_QUADS);
GL11.glVertex2f(100,100);
GL11.glVertex2f(100+200,100);
GL11.glVertex2f(100+200,100+200);
GL11.glVertex2f(100,100+200);
GL11.glEnd();
}
} // class MyAWTGLCanvas