Oxygen Basic
Programming => Example Code => Graphics => Topic started by: Charles Pegge on May 01, 2013, 06:34:17 AM
-
This belongs in the examples/Opengl folder, and demontrates the use of fog, with density and color settings.
/*
http://www.opengl.org/sdk/docs/man2/xhtml/glFog.xml
glfogf int name, float param
GL_FOG_MODE: GL_LINEAR, GL_EXP, and GL_EXP2
GL_FOG_DENSITY: value 1 default
GL_FOG_START: near limit
GL_FOG_END: far limit
GL_FOG_INDEX: color index
GL_FOG_COLOR: array of r g b a
GL_FOG_COORD_SRC:
glEnable / glDisable GL_FOG
*/
includepath "$\inc\"
$ FileName "t.exe"
'include "RTL32.inc"
'include "RTL64.inc"
title="Fog"
include "OpenglSceneFrame.inc"
sub initialize(sys hWnd)
'=======================
SetTimer hWnd,1,10,NULL
end sub
'
sub Triangle
============
glBegin GL_TRIANGLES
glColor3f 1.0, 0.0, 0.0 : glVertex3f 0.0, 1.0, 0.0
glColor3f 0.0, 1.0, 0.0 : glVertex3f -1.0, -1.0, 0.0
glColor3f 0.0, 0.0, 1.0 : glVertex3f 1.0, -1.0, 0.0
glEnd
end sub
sub scene(sys hWnd)
'==================
'
static single s1,s2,s3,s4,ang1,angi1=1,ra,ri
'
glLoadIdentity
glClear GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT
glEnable GL_DEPTH_TEST
glClearColor 0.5, 0.5, 0.7, 0
'
float fcolor[4]={.5, .5, .7, .99}
glfogi GL_FOG_MODE,GL_EXP
glfogf GL_FOG_DENSITY,0.1
glfogfv GL_FOG_COLOR, fcolor
glfogf GL_FOG_INDEX, 0
glfogf GL_FOG_START, -1.0
glfogf GL_FOG_END, -100.0
glEnable GL_FOG
'
glPushMatrix
gltranslatef 6.0, 0.0, -16.0
glrotatef ang1,0,1,0
Triangle
glPopMatrix
'
glPushMatrix
gltranslatef 2.0, 0.0, -8.0
glrotatef ang1,0,1,0
Triangle
glPopMatrix
'
glPushMatrix
gltranslatef 0.0, 0.0, -4.0
glrotatef ang1,0,1,0
Triangle
glPopMatrix
'
ang1+=angi1
if ang1>360 then ang1-=360
'
end sub
sub Release(sys hwnd)
'====================
killTimer hwnd, 1
end sub
-
Hi Charles,
No Fog here!
include "sw.inc"
include "swgl.inc"
Declare glFogfv Lib "opengl32.dll" (int pname, single *params)
hwnd = Window 640,480,1
hdc = InitGL (hwnd)
'GL_FOG_COORD_SRC
sub Triangle
============
glBegin GL_TRIANGLES
glColor3f 1.0, 0.0, 0.0 : glVertex3f 0.0, 1.0, 0.0
glColor3f 0.0, 1.0, 0.0 : glVertex3f -1.0, -1.0, 0.0
glColor3f 0.0, 0.0, 1.0 : glVertex3f 1.0, -1.0, 0.0
glEnd
end sub
sub scene
static single s1,s2,s3,s4,ang1,angi1=1,ra,ri
'
glLoadIdentity
glClear GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT
glEnable GL_DEPTH_TEST
'
float fcolor[4]={.5, .5, .7, .99}
glfogf GL_LINEAR, 0
glfogf GL_FOG_DENSITY,0.1
glfogfv GL_FOG_COLOR, fcolor
glfogf GL_FOG_INDEX, 0
glfogf GL_FOG_START, -1.0
glfogf GL_FOG_END, -100.0
glEnable GL_FOG
'
glPushMatrix
gltranslatef 6.0, 0.0, -1.0
glrotatef ang1,0,1,0
Triangle
glPopMatrix
'
glPushMatrix
gltranslatef 2.0, 0.0, -1.0
glrotatef ang1,0,1,0
Triangle
glPopMatrix
'
glPushMatrix
gltranslatef 0.0, 0.0, -1.0
glrotatef ang1,0,1,0
Triangle
glPopMatrix
'
ang1 += angi1
if ang1>360 then ang1-=360
end sub
glClearColor 0.5, 0.5, 0.7, 0
while Key(27)=0
scene
DoEvents
SwapBuffers hdc
SetFps (60)
wend
QuitGL
CloseWindow
X
-
Use the standard Opengl headers, and you would not have so many problems.
-
I don't have problems, only no fog. :D
-
I have made a correction to this line:
glfogf GL_LINEAR, 0
now:
glfogi GL_FOG_MODE,GL_EXP
See if it works now.
-
Fog by Peter is better. :D
single fcolor[4] = {1.0, 1.0, 1.0, 1.0}
glEnable GL_FOG
glFogi(GL_FOG_MODE, GL_LINEAR)
'glFogf GL_FOG_DENSITY,1.0
glFogfv GL_FOG_COLOR, fcolor
'glFogf GL_FOG_INDEX, 0.0
glFogf GL_FOG_START, 0.0
glFogf GL_FOG_END, 2.0
GL_FOG_DENSITY isn't necessary when only GL_LINEAR is used.