PDA

View Full Version : Difference between GLAnimCanvas and GLAnimJPanel



Mat
06-24-2002, 07:30 AM
Hi,

I try to convert my GLAnimCanvas to a GLAnimJPanel because I need to have a swing component in my application and not an AWT component..

My GLAnimCanvas worked perfectly.. Now I do not arrrive to get the same with a GLAnimJPanel.. All I have is a big black screen...

I also tried with an example of GLAnimJPanel I found and it works correctly.. I do not know what is wrong in my code:

************************************************** ****************************************

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import gl4java.GLContext;
//import gl4java.awt.GLAnimCanvas;
import gl4java.swing.GLAnimJPanel;
import gl4java.*;


public class BarChart extends GLAnimJPanel {

int NumberOfGraduation;
int Indice;


public BarChart(int w, int h,int numberOfGraduation,int indice) {
super();
//super(w,h);
setAnimateFps(60.0f);
NumberOfGraduation = numberOfGraduation;
Indice = indice;
}

public void reshape(int width, int height){
gl.glViewport(0,0,width,height);
gl.glMatrixMode(GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrtho(-1.0f,1.0f,-1.0f,1.0f,1.0f,10.0f);
gl.glMatrixMode(GL_MODELVIEW);
gl.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
gl.glLoadIdentity();
}

public void init() {

gl.glShadeModel(GL_SMOOTH);
gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
gl.glClearDepth(1.0f);
gl.glEnable(GL_DEPTH_TEST);
gl.glDepthFunc(GL_LEQUAL);
gl.glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
}


public void DrawGLScene(){

gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
gl.glTranslatef(-1.0f, -1.0f,-2.0f);

float y_Value = 2.0f/NumberOfGraduation;
float parity = NumberOfGraduation/2.0f;

if(Indice != 1){
for (int i=1; i <= NumberOfGraduation;i++){
gl.glBegin(GL_QUADS);

if (i == 1) gl.glColor3f(0.0f,0.0f,0.4f);
else if (i == NumberOfGraduation) gl.glColor3f(0.85f,0.0f,0.0f);

else if (i != 1 &#0124; &#0124; i!= NumberOfGraduation ){
if (String.valueOf(parity).endsWith("5")) {
if(i == (NumberOfGraduation-3)) gl.glColor3f(1.0f,1.0f,0.0f);
if(i == 4) gl.glColor3f(0.0f,0.4f,0.0f);
if(i == (NumberOfGraduation-2)) gl.glColor3f(1.0f,0.5f,0.0f);
if(i == 3) gl.glColor3f(0.0f,0.0f,1.0f);
if(i == (NumberOfGraduation-1)) gl.glColor3f(1.0f,0.0f,0.0f);
if(i == 2) gl.glColor3f(0.0f,0.0f,0.7f);
if(i == (NumberOfGraduation/2.0f)+0.5) gl.glColor3f(0.0f,0.6f,0.0f);
}
else if (String.valueOf(parity).endsWith("0")) {
if(i == (NumberOfGraduation-3)) gl.glColor3f(1.0f,1.0f,0.0f);
if(i == 4) gl.glColor3f(0.0f,0.4f,0.0f);
if(i == (NumberOfGraduation-2)) gl.glColor3f(1.0f,0.5f,0.0f);
if(i == 3) gl.glColor3f(0.0f,0.0f,1.0f);
if(i == (NumberOfGraduation-1)) gl.glColor3f(1.0f,0.0f,0.0f);
if(i == 2) gl.glColor3f(0.0f,0.0f,0.7f);
if(i == (NumberOfGraduation/2.0f)) gl.glColor3f(0.0f,0.6f,0.0f);
}
}
gl.glVertex3f(0.0f,y_Value,0.0f);
gl.glVertex3f(2.0f,y_Value,0.0f);
gl.glVertex3f(2.0f,0.0f,0.0f);
gl.glVertex3f(0.0f,0.0f,0.0f); // End of the quad
gl.glEnd();
gl.glFlush();
gl.glTranslatef(0.0f, y_Value,0.0f);
}
}

else if(Indice ==1){
for (int i=1; i <= NumberOfGraduation;i++){
gl.glBegin(GL_QUADS);

if (i == 1) gl.glColor3f(0.0f,0.0f,1.0f);
else if (i == NumberOfGraduation) gl.glColor3f(0.0f,0.0f,0.2f);

else if (i != 1 &#0124; &#0124; i!= NumberOfGraduation ){
if(i == (NumberOfGraduation-1)) gl.glColor3f(0.0f,0.0f,0.3f);
else if(i == (NumberOfGraduation-2)) gl.glColor3f(0.0f,0.0f,0.4f);
else if(i == (NumberOfGraduation-3)) gl.glColor3f(0.0f,0.0f,0.5f);
else if(i == (NumberOfGraduation-4)) gl.glColor3f(0.0f,0.0f,0.6f);
else if(i == (NumberOfGraduation-5)) gl.glColor3f(0.0f,0.0f,0.7f);
else if(i == (NumberOfGraduation-6)) gl.glColor3f(0.0f,0.0f,0.8f);
else if(i == (NumberOfGraduation-7)) gl.glColor3f(0.0f,0.0f,0.9f);
}
gl.glVertex3f(0.0f,y_Value,0.0f);
gl.glVertex3f(2.0f,y_Value,0.0f);
gl.glVertex3f(2.0f,0.0f,0.0f);
gl.glVertex3f(0.0f,0.0f,0.0f);
gl.glEnd();
gl.glFlush();
gl.glTranslatef(0.0f, y_Value,0.0f);
}
}
else System.out.println("ERROR: In BarChart.java wrong Indice number in DrawGLScene");

gl.glFlush();
gl.glLoadIdentity();
}

public void setNumberOfGraduation(int numberOfGraduation){
NumberOfGraduation = numberOfGraduation;
}

public void setIndice(int indice){
Indice = indice;
}

public void display() {

glj.gljMakeCurrent(); //Ensure GL is initialised correctly
DrawGLScene();
glj.gljSwap(); //Swap buffers
glj.gljFree(); // release GL
glj.gljCheckGL();
}
}
********************************************
********************************************

Thanks a lot for your help
Mathieu