Author Topic: Simple Window Opengl  (Read 3338 times)

0 Members and 3 Guests are viewing this topic.

Peter

  • Guest
Simple Window Opengl
« on: June 13, 2014, 12:03:20 PM »
Deleted.
« Last Edit: January 28, 2015, 04:24:11 AM by Peter »

Charles Pegge

  • Guest
Re: Simple Window Opengl
« Reply #1 on: June 13, 2014, 12:22:40 PM »
Hi Peter,

This is what I use:
Code: [Select]
  macro AdjustAspect
  ==================
  finit 'intitialise fpu
  GetClientRect  hwnd,cRect
  glViewport 0, 0, crect.right, crect.bottom
  aspect=crect.right/crect.bottom
  end macro

  sub perspective(sys hwnd) label
  ===============================
  glMatrixMode GL_PROJECTION
  glLoadIdentity
  if pick
    gluPickMatrix( mposx, crect.bottom-mposy, 2.0, 2.0, @crect) 'pixel selection zone
  end if
  gluPerspective 45.0, aspect, 1.0, 1.0e9 'viewAngle,aspect,near,far
  glMatrixMode GL_MODELVIEW
  glLoadIdentity
  end sub

Make sure your gluPerspective prototype specifies doubles, not floats

Mike Lobanovsky

  • Guest
Re: Simple Window Opengl
« Reply #2 on: June 14, 2014, 12:55:50 AM »
This is what I use:

....
  gluPerspective 45.0, aspect, 1.0, 1.0e9 'viewAngle,aspect,near,far
....

Charles,

It seems to me that such a terrific depth range can easily cause z-buffer fighting on distant surfaces that appear to be nearly coplanar (been there, seen that). It is generally considered to be safe enough to have the depth range ratio within 1 to a few thousand units. From this perspective, Peter's variant seems much more reasonable than yours.

Alternatively the depth range using gluPerspective() can also be made dynamic based on the current distance between the camera and the scene origin [0,0,0] where most of scene objects are usually clustered: the farther the distance, the larger both near and far plane arguments.

::)

.

Frankolinox

  • Guest
Re: Simple Window Opengl
« Reply #3 on: June 14, 2014, 02:13:46 AM »
I'ver used for example this one some years ago with powerbasic :)

Code: [Select]
Sub ResizeScene (w As Long, h As Long)
       glViewport 0, 0, w, h             'resize viewport
       glMatrixMode %gl_projection       'select projection matrix
       glLoadIdentity                    'reset projection matrix
       gluPerspective 45, w/h, 0.1, 100  'set perspective aspect ratio
       glMatrixMode %gl_modelview        'select modelview matrix
    End Sub

Charles Pegge

  • Guest
Re: Simple Window Opengl
« Reply #4 on: June 14, 2014, 02:53:15 AM »
 Thanks Mike, I'll look into that. - How to represent a bumble bee on a flower, in a landscape with woodland and distant mountains.


Mike Lobanovsky

  • Guest
Re: Simple Window Opengl
« Reply #5 on: June 14, 2014, 03:34:57 AM »
How to represent a bumble bee on a flower, in a landscape with woodland and distant mountains.

Only by skinning the mountain texture onto a nearby screen-sized quad rendered in an ortho projection as the first (background) object in the scene. That's the safest scenario.

Another quite common technique is to use a carefully measured quantity of OpenGL colored fog to emulate haze as shown below.

.

Charles Pegge

  • Guest
Re: Simple Window Opengl
« Reply #6 on: June 14, 2014, 05:24:24 AM »

Ah yes, Wales is a land of mist. To me, any landscape without foggy haze looks unnatural.

Another scenario is the journey to Mars, a trivial distance that does not necessitate warp-drive or teleportation. It is desirable to be able to make this journey without changing the scene geometry, or backdrop.

Mike Lobanovsky

  • Guest
Re: Simple Window Opengl
« Reply #7 on: June 14, 2014, 01:03:05 PM »
Haha, Mars?!

Then a little bit more trolling. :)

If it's Mars that you're after, then a textured quad is an absolute must! You just scale it up and up as you arrive closer and closer until it fills up your entire field of vision as shown in Screen 1 below (in-game view).

Screen 2 shows the technique textured and seen at an angle impossible in the game, and Screen 3 shows the same but untextured and with various scene meshes colored differently to tell them from one another.

8)

.