Oxygen Basic
Programming => Example Code => Topic started by: Peter on June 13, 2014, 12:03:20 PM
-
Deleted.
-
Hi Peter,
This is what I use:
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
-
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 (http://en.wikipedia.org/wiki/Z-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.
::)
.
-
I'ver used for example this one some years ago with powerbasic :)
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
-
Thanks Mike, I'll look into that. - How to represent a bumble bee on a flower, in a landscape with woodland and distant mountains.
-
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.
.
-
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.
-
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)
.