Connect LWJGL to JComponent?

The title pretty much says it all. I want LWJGL to draw to a component in my JFrame, instead of a GLFW window. What's the most efficient way I can make this work, if it is possible? Thank you in advance.
4 Replies
JavaBot
JavaBot10mo ago
This post has been reserved for your question.
Hey @The Typhothanian! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
john
john10mo ago
Code: import com.jogamp.opengl.*; import com.jogamp.opengl.GLCapabilities; import com.jogamp.opengl.awt.GLJPanel; import javax.swing.JFrame;
public class JOGLExample implements GLEventListener {
public static void main(String[] args) {
final GLProfile profile = GLProfile.get(GLProfile.GL2);
GLCapabilities capabilities = new GLCapabilities(profile);

final GLJPanel glpanel = new GLJPanel(capabilities);
JOGLExample triangle = new JOGLExample();
glpanel.addGLEventListener(triangle);
glpanel.setSize(400, 400);

final JFrame frame = new JFrame("Colored Triangle");

frame.getContentPane().add(glpanel);
frame.setSize(frame.getContentPane().getPreferredSize());
frame.setVisible(true);
frame.setSize(1280, 800);
}

@Override
public void init(GLAutoDrawable glad) {
}

@Override
public void dispose(GLAutoDrawable glad) {
}

@Override
public void display(GLAutoDrawable glad) {
final GL2 gl = glad.getGL().getGL2();
gl.glBegin(GL2.GL_POLYGON);

gl.glColor3f(1.0f, 0.0f, 0.0f); // Red
gl.glVertex3f(0.5f, 0.7f, 0.0f); // Top
gl.glColor3f(0.0f, 1.0f, 0.0f); // green
gl.glVertex3f(-0.2f, -0.50f, 0.0f); // Bottom Left
gl.glColor3f(0.0f, 0.0f, 1.0f); // blue
gl.glVertex3f(0.5f, -0.5f, 0.0f); // Bottom Right

gl.glEnd();
}

@Override
public void reshape(GLAutoDrawable glad, int i, int i1, int i2, int i3) {
}
}
public class JOGLExample implements GLEventListener {
public static void main(String[] args) {
final GLProfile profile = GLProfile.get(GLProfile.GL2);
GLCapabilities capabilities = new GLCapabilities(profile);

final GLJPanel glpanel = new GLJPanel(capabilities);
JOGLExample triangle = new JOGLExample();
glpanel.addGLEventListener(triangle);
glpanel.setSize(400, 400);

final JFrame frame = new JFrame("Colored Triangle");

frame.getContentPane().add(glpanel);
frame.setSize(frame.getContentPane().getPreferredSize());
frame.setVisible(true);
frame.setSize(1280, 800);
}

@Override
public void init(GLAutoDrawable glad) {
}

@Override
public void dispose(GLAutoDrawable glad) {
}

@Override
public void display(GLAutoDrawable glad) {
final GL2 gl = glad.getGL().getGL2();
gl.glBegin(GL2.GL_POLYGON);

gl.glColor3f(1.0f, 0.0f, 0.0f); // Red
gl.glVertex3f(0.5f, 0.7f, 0.0f); // Top
gl.glColor3f(0.0f, 1.0f, 0.0f); // green
gl.glVertex3f(-0.2f, -0.50f, 0.0f); // Bottom Left
gl.glColor3f(0.0f, 0.0f, 1.0f); // blue
gl.glVertex3f(0.5f, -0.5f, 0.0f); // Bottom Right

gl.glEnd();
}

@Override
public void reshape(GLAutoDrawable glad, int i, int i1, int i2, int i3) {
}
}
Gradle Imports: implementation 'org.jogamp.jogl:jogl-all-main:2.3.2' implementation 'org.jogamp.gluegen:gluegen-rt-main:2.3.2' It uses JOGL instead of LWJGL, but all I needed was to draw polygons, so whatever.
This message has been formatted automatically. You can disable this using /preferences.
The Typhothanian
The TyphothanianOP10mo ago
ugh. auto format. well, it is good enough
JavaBot
JavaBot10mo ago
Post Closed
This post has been closed by <@801145088830210129>.
Want results from more Discord servers?
Add your server