Jump to content
  • Advertisement
Sign in to follow this  
bugphix

[java] displays only one time?

This topic is 3209 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi, i am trying to run the program below but while the same program runs on other machines by showing the image created constantly, i can see the image created only once on my machine and then it's gone. when i resize the window i can see the display for a second again and then it's gone again. why would this happen? thanks <code> import java.awt.*; import java.awt.event.*; import java.util.Random; import javax.media.opengl.*; import javax.media.opengl.glu.GLU; public class MyProg implements GLEventListener { private Random random = new Random(); GLU glu = new GLU(); Frame frame; GLCanvas canvas; public int width = 640; public int height = 480; public MyProg() { GLCapabilities cap = new GLCapabilities(); cap.setDoubleBuffered(false); canvas = new GLCanvas(cap); canvas.addGLEventListener(this); canvas.setAutoSwapBufferMode(false); frame = new Frame("Trying"); frame.add(canvas); frame.setSize(width, height); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); frame.setVisible(true); } public void init(GLAutoDrawable drawable) { GL gl = drawable.getGL(); gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); gl.glColor3f(1.0f, 0.0f, 0.0f); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); glu.gluOrtho2D(0.0f, 50.0f, 0.0f, 50.0f); gl.glMatrixMode(GL.GL_MODELVIEW); } public void display(GLAutoDrawable drawable) { GL gl = drawable.getGL(); float vertices[][] = {{0.0f,0.0f}, {25.0f,50.0f}, {50.0f,0.0f}}; float p[] = {5.0f, 5.0f}; gl.glClear(GL.GL_COLOR_BUFFER_BIT); gl.glBegin(GL.GL_POINTS); for(int k = 0; k < 400; k++) { int j = random.nextInt(3); p[0] = (p[0] + vertices[j][0]) / 2.0f; p[1] = (p[1] + vertices[j][1]) / 2.0f; gl.glVertex2fv(p,0); } gl.glEnd(); gl.glFlush(); } public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {} public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {} public static void main(String[] args) { new MyProg(); } } </code> I am using Eclipse 3.5.1 as a development environment and jre 6 as my virtual machine

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!