Results 1 to 2 of 2
Thread: Got problem with Java OpenGL
- 05-07-2011, 07:42 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 13
- Rep Power
- 0
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
}
}
-
Duplicate thread with link deleted. Please only one thread per question.
Similar Threads
-
Java GUI problem
By theBurgh22 in forum AWT / SwingReplies: 5Last Post: 03-13-2012, 03:27 PM -
Problem Display Jmenubar Java Se6 u23 versus Java SE6 u22
By Ravanelly in forum Advanced JavaReplies: 0Last Post: 01-07-2011, 09:36 AM -
Q:Applet with graphicWindow using openGL to draw lines,Curves etc
By gsmurthy30 in forum Java AppletsReplies: 1Last Post: 06-30-2010, 07:12 PM -
OpenGl transformation question newbie
By ankitmcgill in forum New To JavaReplies: 1Last Post: 11-16-2008, 03:46 AM -
SWT OpenGL snippet: draw a square
By Java Tip in forum SWTReplies: 0Last Post: 06-28-2008, 09:29 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks