View Full Version : drawing a cube

10-20-2013, 03:12 AM
I am a begginer and I am trying to draw a cube with opengl in java,for that I tried to modify your source posted in tutorials for begginers, that "hello
demo" but does nothing. I want to draw the cube using glutWireCube. Could anyone show me an example for that?

carsten neumann
10-20-2013, 04:05 AM
Not sure which tutorial you are referring to, AFAIK opengl.org does not host tutorials directly, but there is a list of them on the wiki (http://www.opengl.org/wiki/Getting_Started#Tutorials_and_How_To_Guides). I would recommend picking one of those targeting OpenGL 3.0.
Please note that your problem description is not very helpful, so it's not really possible to help, take a look at the Forum Posting Guidelines for suggestions what information to include/how to ask questions.

10-20-2013, 04:46 AM
package glredbook10;

import java.awt.BorderLayout;
import java.awt.Frame;

import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCanvas;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;

import com.sun.opengl.util.Animator;
import com.sun.opengl.util.GLUT;

public class robot extends Frame implements GLEventListener{

public robot() {
super("Basic JOGL Demo");

setLayout(new BorderLayout());
// addWindowListener(this);

setSize(600, 600);
setLocation(40, 40);



public void init(GLAutoDrawable drawable) {
GL gl = drawable.getGL();

gl.glClearColor(0, 0, 0, 0);
gl.glOrtho(0, 1, 0, 1, -1, 1);

public void reshape(GLAutoDrawable drawable,
int x,
int y,
int width,
int height) {

public void displayChanged(GLAutoDrawable drawable,
boolean modeChanged,
boolean deviceChanged) {

public void display(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
GLUT glut=new GLUT();
gl.glColor3f(1, 0, 0);

private void setupJOGL(){
GLCapabilities caps = new GLCapabilities();
GLCanvas canvas = new GLCanvas(caps);

add(canvas, BorderLayout.CENTER);
Animator anim = new Animator(canvas);


public static void main(String[] args) {
robot demo = new robot();
But it does display nothing , why?

carsten neumann
10-20-2013, 08:21 AM
Please use
around source snippets.
Is this code unmodified from the tutorial? There are some oddities in it, for example the orthographic projection matrix should normally be put on the GL_PROJECTION matrix stack. Also, your orthographic projection only projects objects in the [0,0,-1] x [1,1,1] world coordinate cube onto the screen, but your wire cube is entirely outside this volume.