Author Topic: Simple Fog Demo  (Read 3073 times)

0 Members and 2 Guests are viewing this topic.

Charles Pegge

  • Guest
Simple Fog Demo
« 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

« Last Edit: May 01, 2013, 09:21:08 AM by Charles Pegge »

Peter

  • Guest
Re: Simple Fog Demo
« Reply #1 on: May 01, 2013, 08:15:04 AM »
Hi Charles,

No Fog here!
Code: [Select]
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

o2admin

  • Administrator
  • *****
  • Posts: 21
  • OxygenBasic
    • Oxygen Basic
Re: Simple Fog Demo
« Reply #2 on: May 01, 2013, 08:44:51 AM »
Use the standard Opengl headers, and you would not have so many problems.

Peter

  • Guest
Re: Simple Fog Demo
« Reply #3 on: May 01, 2013, 08:57:46 AM »
I don't have problems, only no fog.  :D

Charles Pegge

  • Guest
Re: Simple Fog Demo
« Reply #4 on: May 01, 2013, 09:24:06 AM »
I have made a correction to this line:

 glfogf GL_LINEAR, 0
 
now:

glfogi GL_FOG_MODE,GL_EXP

See if it works now.

Peter

  • Guest
Re: Simple Fog Demo
« Reply #5 on: May 01, 2013, 11:00:42 AM »
Fog by Peter is better.  :D

  
Code: [Select]
 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.
« Last Edit: May 01, 2013, 11:49:11 AM by peter »