scrolling or something like that

Hello,

I have a program that displays comething in 2D on the screen. I have also an independent zoom by the X and Y axis (I can zoom with the mouse wheel in Y and by selection a region from the screen in X).
When the program starts, there are some nombers that are displayed on the screen along the two axis, they represent the coordinates . At the beginning I had a for(i=0; i <END_OF_X_AXIS; i++) to display all the numbers. But this kind of instruction slow down the computer , I have a 100% CPU usage. So I had an idea to draw these numbers only in the region where I’m seeing something (in the projection region) and to draw the rest of the numers when I’m scrolling. I’m using Java SWING JScrollBar, when I’m scrolling, I’m changing X ot Y and I’m using the glTranslate(X,Y,0) function to go to another place over the drawn scene i.e. if I scroll to the right I’m getting the scroll value and placing in the glTranslate(). I’m trying to use this same value to draw the next number that will appear ot the righ side over the X axis. For example on the screen I’m seeing the numbers between 5 and 10. So when I’m scrolling to the right I want to see 11 and the 5 must disapear. Finally I want to see 6 7 … 11.
But … it doesn’t work :frowning: . Sometimes the numbers are over the axis but in a different place or they are not drawn at all.
So, can someone give me an advice how to do this ?

Regards,

Anton

PS. I had also another idea before, it was not to use a scrollbar but to “catch” the sceen and to move it with the mouse in the direction I want, but I didn’t know how something like this can be done with OpenGL.

Well for your main problem you really need to give a bit more information how you implemented things. Posting your code will give you more answers I think.

With regards to the scrolling, this can be done easily by adding a MouseListener: you just store the current mouse coordinates on MousePressed and in the MouseMove you first check if the mouse button is being held down, if so you calculate the difference between the current mouse coordinate and the one stored in MousePressed and you scroll the scene/image by the amount that the mouse was moved.