PDA

View Full Version : Resizing the Line



fuzal
03-22-2012, 01:46 AM
Hello,

I have not too much experience with OpenlGL.

I cannot succeed to resizing or scaling the objects which is drawn on the scene. For example there is a line on the gl Screen and I want to zoom in and zoom out of this line. How can I do it?

If you have a sample code on c# doing this could you please share with me?

Thanks.

ZbuffeR
03-22-2012, 06:21 AM
glScale3d ?

fuzal
03-22-2012, 08:00 AM
I could not succeed with glScale 3d

My code is in C#:

//////////////////////////////////////////////

int screenWidth = 640;
int screenHeight = 480;
int zoomFactor = 1;


public Form1()
{
InitializeComponent();

InitGLScene();
Draw();
}

private void InitGLScene()
{
GL.glEnable(GL.GL_TEXTURE_2D);
GL.glShadeModel(GL.GL_SMOOTH);
GL.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
GL.glClearDepth(1.0f);
GL.glEnable(GL.GL_DEPTH_TEST);
GL.glDepthFunc(GL.GL_LEQUAL);
GL.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
GL.glMatrixMode(GL.GL_PROJECTION);
GL.glOrtho(0, 640, 0, 480, -1, 1);
}

private void Draw()
{
GL.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
GL.glPushMatrix();

GL.glBegin(GL.GL_LINES);
GL.glColor3f(0.5f, 0.5f, 0.0f);
GL.glVertex3f(100.0f, 100.0f, 0.0f);
GL.glVertex3f(200.0f, 200.0f, 0.0f);
GL.glEnd();

GL.glPopMatrix();
GL.glFlush();

openGLControl1.Refresh();
}

private void setProjectionMatrix()
{
int width = screenWidth * zoomFactor;
int height = screenHeight * zoomFactor;

int left = 0 + zoomFactor;
int right = 640 + zoomFactor;
int bottom = 0 + zoomFactor;
int top = 480 + zoomFactor;

GL.glMatrixMode(GL.GL_PROJECTION);
GL.glLoadIdentity();
GL.glOrtho(left, right, bottom, top, -1, 1);

openGLControl1.Refresh();


}

//Zoom In button clicked
private void button1_Click(object sender, EventArgs e)
{
int x = int.Parse(textBox1.Text);
zoomFactor = x;

setProjectionMatrix();

openGLControl1.Refresh();
}
//////////////////////////////////////////////


Could You please help me, how can i zoom in or zoom out and pan on a 2d drawn object?

BionicBytes
03-22-2012, 10:04 AM
I could not succeed with glScale 3d

Why not? What happened and where's your code using glScalef

fuzal
03-22-2012, 11:46 PM
I have used that code:

GL.glScalef((float)this.xScale, (float)this.yScale, (float)this.zScale);

If I use this and then draw again the line it works. But i dont want to make a draw again. I just want to zoom in or zoom out existing area on 2d drawing area. I am using glOrtho() to draw line .

Could you send me a sample code which is making zoom in or zoom out on 2D area.

BionicBytes
03-23-2012, 04:38 PM
GlScalef is a command which modifies the modelview matrix. It is therefore necessary to draw the primitive again for it to be affected by the model view. That's how all 3d rendering works.