Thanks for your answer but this doesn’t seem to work,
If you could check this portion of code :
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLJPanel;
import javax.media.opengl.glu.GLU;
import javax.swing.JFrame;
public class ScissorTest extends JFrame implements GLEventListener
{
private final int H_TIME_SCALE = 20;
private final int H_TIME_SCROLL = 10;
private final int W_TRACK_SCROLL = 10;
private final int W_TRACK_HEADER = 100;
private final int TK_NUMBER = 10;
private float[] bgColor = {1,1,1,1};
private int width;
private int height;
private GLJPanel glp;
private GL gl;
private GLU glu;
private float minY = 0;
private float maxY = 20;
private float minX = 0;
private float maxX = 2000;
public ScissorTest()
{
super("ScissorTest");
setSize(400,400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
glp = new GLJPanel();
glp.addGLEventListener(this);
add(glp);
setVisible(true);
}
public void init(GLAutoDrawable drawable)
{
gl = drawable.getGL();
glu = new GLU();
gl.glShadeModel(GL.GL_SMOOTH); // Enable Smooth Shading
gl.glClearColor(bgColor[0],bgColor[1],bgColor[2],bgColor[3]); // White Background
gl.glViewport(0, 0, width, height);
gl.glEnable(GL.GL_POINT_SMOOTH);
gl.glEnable(GL.GL_LINE_SMOOTH);
gl.glEnable(GL.GL_POLYGON_SMOOTH);
gl.glPolygonMode(GL.GL_FRONT, GL.GL_LINE);
gl.glEnable(GL.GL_BLEND);
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glEnable(GL.GL_SCISSOR_TEST);
}
public void display(GLAutoDrawable drawable)
{
gl = drawable.getGL();
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
gl.glLoadIdentity();
gl.glPolygonMode(GL.GL_FRONT, GL.GL_FILL);
// TIME SCALE
gl.glViewport(W_TRACK_HEADER,height-H_TIME_SCALE,width-W_TRACK_HEADER-W_TRACK_SCROLL,H_TIME_SCALE);
gl.glScissor(W_TRACK_HEADER,height-H_TIME_SCALE,width-W_TRACK_HEADER-W_TRACK_SCROLL,H_TIME_SCALE);
glu.gluOrtho2D(0,1,0,1);
gl.glColor3f(1,0,0);
gl.glRectf(0,0,1,1);
// TRACK HEADER
gl.glViewport(0,H_TIME_SCROLL,W_TRACK_HEADER,height-H_TIME_SCROLL-H_TIME_SCALE);
gl.glScissor(0,H_TIME_SCROLL,W_TRACK_HEADER,height-H_TIME_SCROLL-H_TIME_SCALE);
glu.gluOrtho2D(0,1,0,1);
gl.glColor3f(0,1,0);
gl.glRectf(0,0,1,1);
// TRACK SCROLL
gl.glViewport(width-W_TRACK_SCROLL,H_TIME_SCROLL,W_TRACK_SCROLL,height-H_TIME_SCROLL-H_TIME_SCALE);
gl.glScissor(width-W_TRACK_SCROLL,H_TIME_SCROLL,W_TRACK_SCROLL,height-H_TIME_SCROLL-H_TIME_SCALE);
glu.gluOrtho2D(0,1,0,1);
gl.glColor3f(0,0,1);
gl.glRectf(0,0,1,1);
// TIME SCROLL
gl.glViewport(W_TRACK_HEADER,0,width-W_TRACK_HEADER-W_TRACK_SCROLL,H_TIME_SCROLL);
gl.glScissor(W_TRACK_HEADER,0,width-W_TRACK_HEADER-W_TRACK_SCROLL,H_TIME_SCROLL);
glu.gluOrtho2D(0,1,0,1);
gl.glColor3f(0.5f,0.5f,0);
gl.glRectf(0,0,1,1);
// TRACK DISPLAY
int trackHeight = (height-H_TIME_SCALE-H_TIME_SCROLL)/TK_NUMBER;
gl.glColor3f(0,0,0);
int currentHeight = 0;
for(int i = TK_NUMBER ; i >= 0 ; i--)
{
gl.glViewport(W_TRACK_HEADER,H_TIME_SCROLL+currentHeight,width-W_TRACK_HEADER-W_TRACK_SCROLL,trackHeight);
gl.glScissor(W_TRACK_HEADER,H_TIME_SCROLL+currentHeight,width-W_TRACK_HEADER-W_TRACK_SCROLL,trackHeight);
glu.gluOrtho2D(minX,maxX,minY,maxY);
gl.glBegin(GL.GL_LINES);
gl.glVertex2f(minX,minY);
gl.glVertex2f(maxX,maxY);
gl.glEnd();
currentHeight += trackHeight;
}
}
public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h)
{
width = w;
height = h;
}
public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged){}
public static void main(String args[])
{
new ScissorTest();
}
}
In this code I define different areas, the colored ones are for time scale, scrollbar…
the center is for curve drawing :
what I draw is pretty simple, a simple line going from the left/bottom corner to the right/upper corner of the gluOrtho2D view.
As you can see in the picture attached, on my computer (mac os x) each line is drawn in the same area.
Can you reproduce this ? What am I doing wrong here ?
Thanks for your time.
Léo