Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: From gluOrtho2D to 3D

  1. #1
    Newbie Newbie
    Join Date
    Dec 2014

    From gluOrtho2D to 3D

    Hello everybody,
    I am a newbie with openGL and I am trying to experiment my first project in this field. I followed a guide to draw a Lorenz system in 2D.

    I want now to extend my project and switch from 2D to 3D. As far as I know I have to substitute the gluOrtho2D call with either gluPerspective or glFrustum. Unfortunately whatever I try it's useless.
    This is my initialization code:

    Code :
            // set the background color
    	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    	/*// set the foreground (pen) color
    	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);*/
    	// set the foreground (pen) color
    	glColor4f(1.0f, 1.0f, 1.0f, 0.02f);
    	// enable blending
    	// enable point smoothing
    	// set up the viewport
    	glViewport(0, 0, 400, 400);
    	// set up the projection matrix (the camera)
            //gluOrtho2D(-2.0f, 2.0f, -2.0f, 2.0f);
    	gluPerspective(45.0f, 1.0f, 0.1f, 100.0f); //Sets the frustum to perspective mode
    	// set up the modelview matrix (the objects)

    while to draw I do this:

    Code :
    	// draw some points
    	// go through the equations many times, drawing a point for each iteration
    	for (int i = 0; i < iterations; i++) {
    		// compute a new point using the strange attractor equations
    		float xnew=z*sin(a*x)+cos(b*y);
    		float ynew=x*sin(c*y)+cos(d*z);
    		float znew=y*sin(e*z)+cos(f*x);
    		// save the new point
    		x = xnew;
    		y = ynew;
    		z = znew;
    		// draw the new point
    		glVertex3f(x, y, z);
    	// swap the buffers

    the problem is that I don't visualize anything in my window. It's all black. May you kindly help me figuring out what I do wrong? Thanks in advance!

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Quote Originally Posted by Henry90 View Post
    Code :
    	// set up the modelview matrix (the objects)
    Try adding
    Code :
    	glTranslatef(0, 0, -2);
    immediately after the above code, to move the rendered points in front of the viewpoint.

    gluOrtho2D sets the near distance to -1 (i.e. points can be 1 unit behind the viewpoint and still be rendered), while perspective projections require the near distance to be positive (in this case, it's 0.1). Also, in a perspective projection, points which are very close to the viewpoint won't be visible unless they're roughly in front of it (in this case, within an angle of 22.5 degrees).

    If the attractor is centred on the origin, and the viewpoint is also at the origin, it's entirely possible that everything is outside at least one of the edges of the frustum.

    The attached image shows the difference between the view volumes generated by your gluOrtho2D (red) and gluPerspective (blue) calls.

    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	ortho-perspective.jpg 
Views:	931 
Size:	4.9 KB 
ID:	1539  
    Last edited by GClements; 12-10-2014 at 02:39 PM.

  3. #3
    Newbie Newbie
    Join Date
    Dec 2014
    It works Thanks a lot for your help! you might see me again soon with something similar Thanks once more!

Posting Permissions

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