PDA

View Full Version : Scrolling



gorkv
03-27-2005, 09:21 PM
Have a little problem
I want to draw 2D graphics on my panel


int InitGL ()
{
hDC = GetDC(Panel1->Handle);
SetGLPixelFormat(hDC);
hRC = wglCreateContext(hDC);
wglMakeCurrent(hDC, hRC);
glClearColor(1.0, 1.0, 1.0,
0.0);
glViewport( 0, 0, Panel1->Width, Panel1->Height );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho(-1,1, -1,0, 2,12);
gluLookAt(0,0,5, 0,0,0, 0,1,0);
glMatrixMode( GL_MODELVIEW );
return 0;
}

void Draw (double *y, double dx, int n)
{
int i;
double x = 0, m;
glClear((GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT));
glColor3f (1, 0, 0);
for (i = 0; i < n; i++)
{
if (fabs (y[i]) > x)
x = fabs (y[i]);
}
m = x;
x = 0;
glBegin (GL_LINES);
glVertex2f ( y[0] / m, 0);
for (i = 1; i < n; i++)
{
glVertex2f ( y[i] / m, - _koef_*x / (n * dx));
glVertex2f ( y[i] / m, - _koef_*x / (n * dx));
x += dx;
}
glEnd ();

}For some values of _koef_ it cannot be displayed wholly. So I need to organize scrollbars on Panel1. How must I do this.
Please give me an example on what I have to write in OnScroll event procedure.
One more question: how to organize zooming on selected area of a graphic?

Thanks.
PS Sorry for my bad english.