OpenGL examples oxygen

Started by Frank Brübach, October 22, 2023, 09:25:30 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Frank Brübach

  '
Hey all Here I want to Like Show some simple oxygenbasic examples created with OpenGL

'openGL example pyramid + cube by frank brübach, 22-10-2023
  ' oxygenbasic
  '
  includepath "$\inc\"
  $ FileName "t.exe"
  'include  "RTL32.inc"
  'include  "RTL64.inc"
  $ title    "Rotating cube + pyramid"
  int width=640
  int height=480
  #include "OpenglSceneFrame.inc"


  sub Initialize(sys hWnd)
  '=======================
  end sub
  '

  procedure drawPyramid() 'test
  =======================
  static single ang1,angi1
  static single framecounter

  framecounter++
  gltranslatef -0.5,0.5,-1
  glrotatef angi1,0.0,1.0,0.0
  'glscalef    0.01,0.01,0.01
  glscalef    1.5,1.5,1.5
  glBegin GL_TRIANGLE_FAN
    glColor3f  0, 128, 255 : glVertex3i  0.0,  1.0,  0.0
    glColor3f 255,  0,  0 : glVertex3i -1.0, -1.0,  1.0
    glColor3f 255, 255, 255 : glVertex3i  1.0, -1.0,  1.0
    glColor3f  0,  0, 255 : glVertex3i  1.0, -1.0, -1.0
    glColor3f  0, 255,  0 : glVertex3i -1.0, -1.0, -1.0
    glColor3f 255,  0,  0 : glVertex3i -1.0, -1.0,  1.0
  glEnd
  angi1 += 180.0/framecounter
end procedure

  sub Scene(sys hWnd)
  '==================
  '
  static single ang1,angi1=1
  '
  NewFrame
  glClearColor 0.5, 0.5, 0.7, 0.0
  glClear GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT
  Fog          0.5, 0.5, 0.7, 0.05 'rgb and density
 
  glLoadIdentity
  gltranslatef    -1.0, 0.0, -6.0 '-4.0
  glrotatef ang1, 0.0, 0.0,  1.0
  '
  ''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

    glLoadIdentity
    gltranslatef    2.0, 0.0, -6.0
    glscalef 0.75,0.75,0.75
    glrotatef ang1, 0.0, 1.0,  1.0
   
  glBegin GL_QUADS          ' Drawing using Quads
    ' Top Quad
    glColor3f 0, 255, 0          ' Green   
    glVertex3f  1.0,  1.0, -1.0  ' Top Right
    glVertex3f -1.0,  1.0, -1.0  ' Top Left
    glVertex3f -1.0,  1.0,  1.0  ' Bottom Left
    glVertex3f  1.0,  1.0,  1.0  ' Bottom Right

    ' Bottom Quad
    glColor3f 255, 127, 0        ' Orange   
    glVertex3f  1.0, -1.0,  1.0  ' Top Right
    glVertex3f -1.0, -1.0,  1.0  ' Top left
    glVertex3f -1.0, -1.0, -1.0  ' Bottom Left
    glVertex3f  1.0, -1.0, -1.0  ' Bottom Right

    ' Front Quad
    glColor3f 255, 0, 0          ' Red   
    glVertex3f  1.0,  1.0,  1.0  ' Top Right
    glVertex3f -1.0,  1.0,  1.0  ' Top Left
    glVertex3f -1.0, -1.0,  1.0  ' Bottom Left
    glVertex3f  1.0, -1.0,  1.0  ' Bottom Right

    ' Back Quad
    glColor3f 255, 255, 0        ' Yellow
    glVertex3f  1.0, -1.0, -1.0  ' Bottom Left
    glVertex3f -1.0, -1.0, -1.0  ' Bottom Right
    glVertex3f -1.0,  1.0, -1.0  ' Top Right
    glVertex3f  1.0,  1.0, -1.0  ' Top Left
   
    ' Left Quad
    glColor3f 0, 0, 255          ' Blue
    glVertex3f -1.0,  1.0, -1.0  ' Top Right
    glVertex3f -1.0, -1.0, -1.0  ' Top Left
    glVertex3f -1.0, -1.0,  1.0  ' Bottom Left
    glVertex3f -1.0,  1.0,  1.0  ' Bottom Right
   
    ' Right Quad
    glColor3f 255, 0, 255        ' Violet
    glVertex3f  1.0,  1.0, -1.0  ' Top Right
    glVertex3f  1.0,  1.0,  1.0  ' Top Left
    glVertex3f  1.0, -1.0,  1.0  ' Bottom Left
    glVertex3f  1.0, -1.0, -1.0  ' Bottom Right
 
  glEnd
 
  'UPDATE ROTATION ANGLES
  '----------------------
  '
  glLoadIdentity
  gltranslatef    -1.0, 0.0, -6.0 '-4.0
 
  drawpyramid()
  ang1+=angi1
  if ang1>360 then ang1-=360
  '
  end sub

  sub Release(sys hwnd)
  '====================
  end sub

Frank Brübach

#1
Next example topic "translucent" Texture
Picture you find below place IT in Same folder Demos/opengl

  '--- cubeLighting with translucent effect, oxygenbasic
  ' 23-10-2023 by frank brübach
  ' based on crateLighting example
  '
  $ FileName "t.exe"
  'uses rtl32
  'uses rtl64
  %ExplicitMain
  $ title  "Cubes translucents"
  'uses glTransA
  uses OpenglSceneFrame
 
  indexbase 1
  sys  texn[3]
  sys  GdiplusToken
  float ang1
  float li[16]
  float ma[13]
  sys cube pent


  macro TranslucentMaterial(ma,alpha)
  ===================================
  static float ma={
  0.7, 0.70, 0.70, alpha, 'diffuse
  .15, 0.15, 0.15, alpha, 'ambient
  0.1, 0.10, 0.10, alpha, 'specular 
  0.                      'shininess
  }
  Material ma
  end macro

  sub initialize(sys hWnd)
  ========================
  '
  'GDIPLUS
  '
  sys hr
  GdiplusStartupInput StartupInput

  StartupInput.GdiplusVersion = 1
  hr=GdiplusStartup GdiplusToken, StartupInput, null
  '
  if hr then
    print "Error initializing GDIplus: " hex hr
    exit function
  end if
  '
  'PREPARE TEXTURES
  '
  glGenTextures 2, texn
  '
  static sys res=256
  string imgs[1]=""
  ''LoadPixImage "../images/crate.jpg",res,imgs[1]
  'LoadPixImage "../images/avengers256.jpg",res,imgs[1]
  LoadPixImage "avengers256.jpg",res,imgs[1]
  MakeTexture *imgs[1],res,res,texn[1]
  '
  cube=CompileList : CubeForm    : glEndList
  pent=CompileList : Sides 5,1,1 : glEndList
  '
  'standard lighting
  ------------------
  li<=
  0.0, 8.0, 8.0, 1.0,  'position
  1.0, 1.0, 1.0, 1.0,  'diffuse
  1.0, 1.0, 1.0, 1.0,  'ambient
  1.0, 1.0, 1.0, 1.0  'specular

  'standard material
  ------------------
  ma<=
  0.7, 0.7, 0.6, 1.0, 'diffuse
  .15, .15, 0.2, 1.0, 'ambient
  0.0, 0.0, 0.1, 1.0, 'specular 
  0                  'shininess
  Material ma
  Lighting li
  '
  end sub

  sub Release(sys hwnd)
  '====================
  glDeleteLists    cube,1
  glDeleteLists    pent,1
  glDeleteTextures 2, texn
  GdiplusShutdown GdiplusToken
  end sub

  sub RenderCrate(float x,y,z,sc,sys tex)
  =======================================
  'glColor4f .99,.99,.99,.99
 
  glEnable GL_TEXTURE_2D
  glBindTexture GL_TEXTURE_2D,tex
  glPushMatrix
  gltranslatef x+0.25,y-0.15,z
  glrotatef    ang1,0,1,0
  glscalef sc*1.25,sc*1.25,sc*1.25
  'glscalef 1.5,1.5,1.5
  glCallList Cube
  'glCallList Pent
  glPopMatrix
  glDisable GL_TEXTURE_2D
  end sub


  sub scene(sys hWnd)
  '==================
  '
  static single ra,ri,angi1=.5
  '
  SnapShots hWnd 'Ctrl-P take snapshot
  NewFrame
  glClearColor 0.5, 0.5, 0.7, 0.0
  'Fog          0.5, 0.5, 0.7, 0.05 'rgb and density
  '
  StandardLighting li
  TranslucentMaterial  mt,0.5
  glEnable GL_LIGHTING
  glEnable GL_NORMALIZE
  glenable GL_BLEND
  glBlendfunc GL_SRC_ALPHA, GL_ONE or GL_ONE_MINUS_SRC_ALPHA
  'glColoralpha 255, 255, 255, 127
  glColor4f .99,.99,.99,.99
  sys n=texn[1]
  RenderCrate  11.5,-0.9,-24.0,0.5,n
  RenderCrate  6.5,-0.9,-16.0,0.5,n
  RenderCrate  2.5,-0.9,-8.0, 0.5,n
  RenderCrate  0.5,-0.9,-4.0, 0.5,n
  RenderCrate  -0.5,-0.9,-2.0, 0.5,n
  RenderCrate  1.25,0.9,-6.0, 0.5,n
  '
  ang1+=angi1
  if ang1>360 then ang1-=360
  sleep 10
  end sub

  MainWindow 740,580,WS_OVERLAPPEDWINDOW