Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: Resizing the Line

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2012
    Location
    Tr
    Posts
    3

    Resizing the Line

    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.

  2. #2
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,655

    Re: Resizing the Line

    glScale3d ?

  3. #3
    Junior Member Newbie
    Join Date
    Mar 2012
    Location
    Tr
    Posts
    3

    Re: Resizing the Line

    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?

  4. #4
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,171

    Re: Resizing the Line

    I could not succeed with glScale 3d
    Why not? What happened and where's your code using glScalef

  5. #5
    Junior Member Newbie
    Join Date
    Mar 2012
    Location
    Tr
    Posts
    3

    Re: Resizing the Line

    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.

  6. #6
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,171

    Re: Resizing the Line

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •