Results 1 to 2 of 2
  1. #1
    Igbear is offline Member
    Join Date
    Nov 2010
    Posts
    13
    Rep Power
    0

    Default Got problem with Java OpenGL

    Greetings!
    For a school task within graphics programming, I am supposed to program a graphics image consisting of multiple circles, which together create a much bigger circle. Or more correctly: Many rings, that together create a huge ring. An image would have helped explain, but I couldn't copy it from the PDF that describes the task (doh!).

    For the drawDLScene(....)-method, I've created another method for generating each circle. A for-loop will (in theory) ensure the right amount of circles are drawn, as well as correct positioning. However, only the first circle is drawn, and I can't seem to find out what I do wrong. (debugging shows that all for-loops are run through correctly, still only the first circle gets drawn).
    Additional info: Each circle change color gradually from black to white.

    This is the code:


    import java.awt.*; // klassene Color og Graphics
    import javax.swing.*; // klassene JFrame og JPanel
    import java.util.*;
    import javax.media.opengl.*; //JOGL klasser
    import javax.media.opengl.glu.*; //glu klasser

    class Window extends JFrame {
    public Window(String tittel) {
    setTitle(tittel);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    PictureOv1_1JOGL tegningen = new TegningOv1_1JOGL(800, 800);
    add(tegningen);
    pack();
    }
    }

    class Task1b{
    public static void main(String[] args){
    Window a = new Window("V2005 Oving 3");
    a.setVisible(true);
    }
    }

    class PictureOv1_1JOGL extends JPanel implements GLEventListener{

    private GLCanvas canvas;
    private float angle;
    private GLU glu = new GLU();

    public PictureOv1_1JOGL(int width, int hight){
    super();

    GLCapabilities capabilities = new GLCapabilities();
    capabilities.setHardwareAccelerated(true);
    capabilities.setDoubleBuffered(true);
    canvas = new GLCanvas(capabilities);
    canvas.addGLEventListener(this);
    this.add(canvas);
    this.setSize(width, hight);
    this.setVisible(true);
    canvas.setSize(width, hight);
    canvas.setVisible(true);
    }

    public void init(GLAutoDrawable glDrawable){
    GL gl = glDrawable.getGL(); //Get the GL object from glDrawable
    gl.glClearColor(0.5f, 0.5f, 0.5f, 0.5f);

    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glLoadIdentity();
    glu.gluPerspective(45.0, 1.0, 2.0, 20.0);
    gl.glMatrixMode(GL.GL_MODELVIEW);
    }

    public void reshape(GLAutoDrawable glDrawable, int i, int i1, int i2, int i3){
    //Has to be implemented due to the GLEventListener interface
    }

    public void drawGLScene(GLAutoDrawable glDrawable){
    GL gl = glDrawable.getGL();
    gl.glClear(GL.GL_COLOR_BUFFER_BIT|GL.GL_DEPTH_BUFF ER_BIT);
    gl.glLoadIdentity();
    gl.glTranslatef(-1.5f, 0.0f, -8.0f);
    int max = 30;
    for (int i=0; i<maks; i++){
    drawCircle(glDrawable, i, max);
    }
    }

    public void drawCircle(GLAutoDrawable glDrawable, int i, int max){
    GL gl = glDrawable.getGL();
    final double PI = 3.1415926535898;

    gl.glLoadIdentity();
    float potitionnumber = (float) ((i+1)/max);
    float angle1 = 2 * (float) PI * posisjonnumber;
    gl.glTranslatef(2.0f*(float) Math.cos(angle1), 2.0f*(float) Math.sin(angle1), -11.0f);
    float colornumber=(float) (i/max);
    gl.glColor3f(colornumber, colornumber, colornumber);
    gl.glBegin(GL.GL_LINE_LOOP);
    double angle2 = 0.0;
    for(int j=0; j<100;j++){ //For loop
    angle2 = 2 * PI * j/100; //Calculate new angle
    gl.glVertex3f(0.5f*(float) Math.cos(angle2), 0.5f*(float) Math.sin(angle2), 0.0f); //Calculate vertex points on the circle
    }
    gl.glEnd();
    }

    public void display(GLAutoDrawable glDrawable){
    GL gl = glDrawable.getGL();
    drawGLScene(glDrawable);
    glDrawable.swapBuffers();

    gl.glFlush();
    }

    public void displayChanged(GLAutoDrawable glDrawable, boolean b, boolean b1){
    //Must be present due to the GLEventListener interface
    }
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Java GUI problem
    By theBurgh22 in forum AWT / Swing
    Replies: 5
    Last Post: 03-13-2012, 04:27 PM
  2. Problem Display Jmenubar Java Se6 u23 versus Java SE6 u22
    By Ravanelly in forum Advanced Java
    Replies: 0
    Last Post: 01-07-2011, 10:36 AM
  3. Replies: 1
    Last Post: 06-30-2010, 08:12 PM
  4. OpenGl transformation question newbie
    By ankitmcgill in forum New To Java
    Replies: 1
    Last Post: 11-16-2008, 04:46 AM
  5. SWT OpenGL snippet: draw a square
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 06-28-2008, 10:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •