OpenGL Font question

Started by Frank Brübach, October 12, 2023, 05:26:13 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Frank Brübach

Hi all how I can move a Font with gprint from left to right Side of OpenGL example ?

Frank Brübach

Quote from: Frank Brübach on October 12, 2023, 05:26:13 PMHi all how I can move a Font with gprint from left to right Side of OpenGL example ?
'...

glPushMatrix
  glLoadIdentity
  PickLabel    100
  gltranslatef -.5,.35,-1.0
  float w,h
  glscalef     .07,.07,.01
  GetWordArea  "Cone: ",w,h
  if pick
    PutBoxArea   w,h
  elseif picked
    glColor3f    .99,.99,.00
    gprint "Cone "
    'gprint*2*sin(cnt1)       " Cone: "
'-----------------                                 
      '' Pulsing Colors Based On Text Position
      'glColor3f 1.0*(cos(cnt1)), 1.0*(sin(cnt2)), 1.0-0.5*(cos(cnt1+cnt2))
      'gPrint "Nehe",280+250*cos(cnt1), 235+200*sin(cnt2) ', "NeHe", 0    '' Print GL Text To The Screen
'-----------------
    glColor3f    .99,.99,.99
    gprint       picked
  end if
  glPopMatrix
  '
'-------------------------
      'glColor3f 1.0,1.0,1.0      '' Set Color To White
      'gPrint "Giuseppe D'Agata",242+200*cos((cnt2+cnt1)/5), 2

      cnt1 = cnt1 + 0.01                                     '' Increase The First Counter
      'cnt2 = cnt2 + 0.0081         
'----------------------------

  EndPick
  '-------------------------

Regards

Charles Pegge

Change the x coordinate value here:

  gltranslatef -.5,.35,-1.0
-->
  gltranslatef .25,.35,-1.0

Frank Brübach

Sorry charles my mistake dont have declare the Problem clear...

Meaning a running Word or Text with

Do... Loop while Complex...

Regards

Frank Brübach

#4
I have used TextureHoles.o2bas example / OpenGL.
My Idea was to get running Word area of cone 1 for example running by a do... Loop / If Key = chr(255)+ "k" then Exit do.,. construct or Something Else to make Text running
Regards

Charles Pegge

As an example you could add a frame counter:

  glLoadIdentity
  static int framecount
  framecount++
  gltranslatef -.5,.25,-1.0
  glColor3f    .99,.50,.50
  glscalef     .06,.06,.01
  gprint       str(framecount)
  '

-->


  $ FileName  "t.exe"
  'uses rtl32
  'uses rtl64
  '
  % ExplicitMain
  % title     "Pick and display cone number"
  % fontA     "Arial",FW_SEMIBOLD

  'macro keydown
  'case 27 : 'no action
  'case 32 : 'no action
  'end macro
  '
  uses OpenglSceneFrame
  uses glo2\Textures

  indexbase 1
  float     ang1
  sys       cube,pent
 

  sub initialize(sys hWnd)
  ========================
  '
  '
  GDIplus 1
  '
  'PREPARE TEXTURES
  '
  '
'/*
  glGenTextures 16, texn
  static sys res=256,texspace
  texspace=res*res*4
  string imgs[2]
  imgs[1]=nuls texspace
  'LoadPixImage "../images/crate.jpg",res,imgs[1]
  '
  'pixbase,width,height,stride,colorval,offset
  --------------------------------------------
  AddNoiseC strptr imgs[1],res,res,32,050,050,100,-2,0x53535353
  AddNoiseC strptr imgs[1],res,res,08,050,050,100, 0,0x35353535
  AddNoiseC strptr imgs[1],res,res,04,070,070,050, 0,0x53535353
  MakeTexture strptr imgs[1],res,res,texn[10]

'*/
'BuildTextures 16,256
  '
  pent=CompileList : Sides 5,1,1 : glEndList
  cube=CompileList : CubeForm    : glEndList
  '
  end sub

  sub Release(sys hwnd)
  '====================
  DeleteAllGlCompiled
  glDeleteTextures 16, texn
  Gdiplus 0
  end sub

  sub ConeNorm(float xb,xe,y,zb,ze,sm)
  ====================================
  'Configured As Front Face
  float zd=zb-ze
  glBegin GL_QUADS
  glNormal3f   -sm , zd  , y : glTexCoord2f 0.0 , 0.0 : glVertex3f -xb , 0 , zb 
  glNormal3f    sm , zd  , y : glTexCoord2f 1.0 , 0.0 : glVertex3f  xb , 0 , zb 
  glNormal3f    sm , zd  , y : glTexCoord2f 1.0 , y   : glVertex3f  xe , y , ze 
  glNormal3f   -sm , zd  , y : glTexCoord2f 0.0 , y   : glVertex3f -xe , y , ze
  glEnd
  end sub

  sub ConeSides(sys n,float xb,xe,y,sm)
  =====================================
  float rb=1.0,re=xe/xb
  float w=tan(pi/n)
  float a=360/n
  int i
  for i=1 to n
  ConeNorm xb*w,xe*w,y,rb,re,sm
  glRotatef a,0,1,0 'anticlockwise
  next
  end sub

  sub RenderCone(float x,y,z,sc,rz,ry,sys n,sm,tex)
  =================================================
  glBindTexture GL_TEXTURE_2D,tex
  glPushMatrix
  gltranslatef  x,y,z
  glrotatef     ang1,0,1,0
  glscalef      sc,sc,sc
  ConeSides     n,1.0,rz,ry,sm
  glPopMatrix
  end sub

  sub RenderPlane(float su,sv, eu,ev)
  ===================================
  eu+=su : ev+=sv
  glBegin GL_QUADS
  glNormal3f 0.0,1.0,0.0
  glTexCoord2f su,sv : glVertex3f -1.0,0,-1.0
  glTexCoord2f eu,sv : glVertex3f  1.0,0,-1.0
  glTexCoord2f eu,ev : glVertex3f  1.0,0, 1.0
  glTexCoord2f su,ev : glVertex3f -1.0,0, 1.0   
  glend
  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
  glColor4f .99,.99,.99,.99
  BeginPick
  StandardLighting li
  StandardMaterial ma
  '
  indexbase 1
  sys   t1=texn[10]'texture
  sys   n=10       'sides
  float ra=0       'top/base ratio
  float ry=2.0     'height/base ratio
  float sm         'smoothing by Normal x adjustment
  '
  glEnable GL_TEXTURE_2D

  'shape locate x,y,z,size,ra,ry,nside,norm,tex
  ---------------------------------------------
  '
  sm=0
  PickLabel 4 : RenderCone  6.5,-0.9,-16.0, 0.5,ra,ry,n,sm,t1
  PickLabel 3 : RenderCone  2.5,-0.9,-8.0 , 0.5,ra,ry,n,sm,t1
  PickLabel 2 : RenderCone  0.5,-0.9,-4.0 , 0.5,ra,ry,n,sm,t1
  PickLabel 1 : RenderCone -0.5,-0.9,-2.0 , 0.5,ra,ry,n,sm,t1
  '
  PickLabel 0
  '
  'PLANE
  glPushMatrix
  glTranslatef  0.0,-2.0,-20.0
  glScalef      16.,1.,16.
  glBindTexture GL_TEXTURE_2D,t1
  RenderPlane   0.,0.,8.,8.
  glPopMatrix
  '
  glDisable GL_TEXTURE_2D
  glDisable GL_LIGHTING
  '
  glPushMatrix
  '
  glLoadIdentity
  static int framecount
  framecount++
  gltranslatef -.5,.25,-1.0
  glColor3f    .99,.50,.50
  glscalef     .06,.06,.01
  gprint       str(framecount)
  '
  glLoadIdentity
  PickLabel    100
  gltranslatef -.5,.35,-1.0
  float w,h
  glscalef     .07,.07,.01
  GetWordArea  "Cone:",w,h
  if pick
    PutBoxArea   w,h
  elseif picked
    glColor3f    .99,.99,.00
    gprint       "Cone: "
    glColor3f    .99,.99,.99
    gprint       picked
  end if
  glPopMatrix
  '
  EndPick
  '
  ang1+=angi1
  if ang1>360 then ang1-=360
  sleep 10
  end sub

  MainWindow width,height,WS_OVERLAPPEDWINDOW

Frank Brübach

#6
Thank you Charles good Idea with framerate. I wanted translate nehe 17 example to oxygen. More to come later Bye regards Frank nice Weekend

PS btw perhaps oxygen needs a good Game to make IT more popular including loading mtl stl 3d Objects. My knowledge ist too Low at the Moment for such an Experiment lol .

Frank Brübach

#7
Hey all Made this oxygen example based upon cratelighting.o2bas ... But IT doesnt Work cannot See gprint on Screen... Bmpfont I send as attachement
  $ FileName "t.exe"
  'uses rtl32
  'uses rtl64
  $ title  "Crates and textRun in Fog"
  uses OpenglSceneFrame

  indexbase 1
  sys  texn[4]
  sys  GdiplusToken
  float ang1
  float li[16]
  float ma[13]
  sys cube pent


  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 3, texn
  '
  static sys res=256
  string imgs[1]=""
  string imgx[1]=""
  LoadPixImage "../images/crate.jpg",res,imgs[1]
  MakeTexture *imgs[1],res,res,texn[1]
  '
  LoadPixImage "../images/bmpfont.bmp",res,imgx[1]
  MakeTexture *imgx[1],res,res,texn[2]

  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,y,z
  glrotatef    ang1,0,1,0
  glscalef sc,sc,sc
  glCallList Cube
  'glCallList Pent
  glPopMatrix
  glDisable GL_TEXTURE_2D
  end sub


  sub scene(sys hWnd)
  '==================
  '
  static single ra,ri,angi1=.5
  static int framerate
  static int textrun
  '
  textrun=50
  '
  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
  '
  'glEnable GL_BLEND true
  glEnable GL_LIGHTING
  glEnable GL_NORMALIZE
  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
  ' 
'------------------------ new for a test -------------------- //
  sys t=texn[2]
  glEnable GL_TEXTURE_2D
  glBindTexture GL_TEXTURE_2D,t

  framecount++
  'gltranslatef -.5, .25,-1.0
  gltranslatef 1.5, .55,-4.0
  glcolor3f .99,.50,.50
  glscalef .06,.06, .01
  gprint "frames: "+str(framecount)

    glColor3f 255,128,0
    'gprint "Fat",14,6
    gprint "Fat",2.0,4.0

    glColor3f 0,0,255
    gprint "Oxygen BASIC",18,6

    glEnable GL_BLEND true
    glColor3f 255,255,0
    gprint "- using print feature -",8,8+sin(gettickcount)
    glEnable GL_BLEND false

    Textrun -= 10 / framecount
   
    if textrun < -100 then textrun = 50
    glcolor3f 255,255,255
    gprint "oxygenBasic - compiler with no limits", textrun, 25

'-------------------------------------------------------- test ends -- //

  ang1+=angi1
  if ang1>360 then ang1-=360
  sleep 10
  end sub
Any Help is Welcome thx

Charles Pegge

Hi Frank,

The main problem was not declaring FontA. Also need to disable GL_LIGHTING, and glLoadIdentity to reset the transform matrix


  $ FileName "t.exe"
  'uses rtl32
  'uses rtl64
  $ title  "Crates in Fog"
  $ fontA     "Arial",FW_SEMIBOLD
  uses OpenglSceneFrame

  indexbase 1
  sys   texn[3]
  sys   GdiplusToken
  float ang1
  float li[16]
  float ma[13]
  sys cube pent


  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]
  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,y,z
  glrotatef    ang1,0,1,0
  glscalef sc,sc,sc
  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
  '
  'TEXT
  glDisable GL_LIGHTING
  glLoadIdentity
  static int framecount
  framecount++
  gltranslatef -.50, .35,-1.0
  glcolor3f .99,.50,.50
  glscalef .06,.06, .01
  'glcalllist cube
  gprint "frames: "+str(framecount)
  '
  'CRATES
  glLoadIdentity
  sys t=texn[2]
  glEnable GL_TEXTURE_2D
  glBindTexture GL_TEXTURE_2D,t

  glEnable GL_LIGHTING
  'glEnable GL_NORMALIZE
  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
  '
  ang1+=angi1
  if ang1>360 then ang1-=360
  sleep 10
  end sub

Charles Pegge

#9
Another demo using fonts to display data. You can drag the triangle points and change the metrics dynamically.

'#compact
 '%filename "t.exe"
 'uses RTL64
 '% Title "Intersection Demo"
  % Title "Triangle Data:  Move points with mouse and arrow keys etc"

 '% WindowStyle WS_OVERLAPPEDWINDOW
 '% Animated
 '% ScaleUp
  % PlaceCentral
  % AnchorCentral

  % shaders

  uses consoleG
 'uses glo2/geoplanar
 
  'Keys: Esc, arrow-keys, n,m, F4

  BeginScript

  procedure main()
  ================

  'WaitForEvent '0 off 1 on (default on)
  static quad t1,t2

  if opening 'FIRST CALL ONLY
    timemark t1
    'picked=100
    'mbox "helo"
  end if
  '
  if closing 'FINAL CALL BEFORE SHUTDOWN
    'mbox "Bye!"
    exit sub
  end if
  cls
  shading
  UserMovement mu,1100,3 'symbol identity, count
  if opening
    mu[1].x= 0
    mu[1].y= 5
    mu[2].x=-5
    mu[2].y=-5
    mu[3].x= 5
    mu[3].y=-5
  endif
  scale 1
  picklabel 0
  int i
  for i=1 to 3
    pushstate
    mu[i].act
    color 1,.9,0,1
    scale 0.4
    go sphere
    popstate
  next
  float xa,xb,xc,ya,yb,yc
  xa=mu[1].x : ya=mu[1].y
  xb=mu[2].x : yb=mu[2].y
  xc=mu[3].x : yc=mu[3].y
  '
  'MOUSE DRAG ADJUSTMENT
  select picked
    case 1100 : xa+=mu[1].d.x : ya+=mu[1].d.y
    case 1200 : xb+=mu[2].d.x : yb+=mu[2].d.y
    case 1300 : xc+=mu[3].d.x : yc+=mu[3].d.y
  end select
  flat
  thickness 2
  '
  color 1,1,0,1
  pushstate
  move xa-.5,ya-1
  gprint "A"
  popstate
  pushstate
  move xb+1,yb+1
  gprint "B"
  popstate
  pushstate
  move xc-1,yc+1
  gprint "C"
  popstate
  '
    color .8,.0,.8
  float zp=-1.001
  glBegin GL_TRIANGLES
  glVertex3f xa,ya,zp
  glVertex3f xb,yb,zp
  glVertex3f xc,yc,zp
  glEnd
  '
  color 0,.9,.9
  glBegin GL_LINES
  glVertex2f xa,ya
  glVertex2f xb,yb
  glVertex2f xb,yb
  glVertex2f xc,yc
  glVertex2f xc,yc
  glVertex2f xa,ya
  glEnd


  move 5

  'if not pick then
    if key[49] then picked=100 'keypress '1'
    if key[50] then picked=200 'keypress  '2'
    pushstate
    move -20,12
    static sys tally
    timemark t2
    scale 1.0
    '
    int dp=3
    '
    macro pr1(a) 'PRINTING LIST
    -----------------------------
      pushstate : color .5,1,1 : print a : popstate
      printl ""
    end macro
    '
    macro pr2(a,b) 'PRINTING LIST
    -----------------------------
      pushstate : color .5,1,1 : print a : popstate
      pushstate : color 1,1,.5 : move 4 : print str(b,dp) : popstate
      printl ""
    end macro
    '
    macro pr3(a,b,c) 'PRINTING LIST
    ------------------------------
      pushstate : color .5,1,1 : print a : popstate
      pushstate : color 1,1,.5 : move 4 : print str(b,dp) : popstate
      pushstate : color 1,1,.5 : move 8 : print str(c,dp) : popstate
      printl ""
    end macro
    '
    '
    'DISPLAY INFO
    -------------
    picklabel 0

    pushstate
    scale 2
    color 1,1,1
    print "Triangle Data"
    popstate
    pr1 ""
    pr1 ""
  'pr2 "Action Code:  ", act
  'pr2 "indexbase      ", indexbase
  'pr2 "Keyboard Code: ", keyd
    pr2 "Picked ID:    ", picked
    '
    pr3 "Point A: ", str(xa,3), ya
    pr3 "Point B: ", str(xb,3), yb
    pr3 "Point C: ", str(xc,3), yc
    '
    float ab,ac,bc,ar,ht,hb
    '
    ab=hypot(xa-xb, ya-yb)
    ac=hypot(xa-xc, ya-yc)
    bc=hypot(xb-xc, yb-yc)
    '
    hb=0.5* ( ab*ab - ac*ac + bc*bc ) / bc
    ht=sqr(ab*ab-hb*hb)
    ar=0.5*bc*ht

    'ANGLES
    float na,nb,nc
    nb=deg(asin(ht/ab))
    nc=deg(asin(ht/ac))
    na=180-nb-nc

    pr1 ""
    pr2 "Angle A:",na
    pr2 "Angle B:",nb
    pr2 "Angle C:",nc
   
    pr1 ""
    pr2 "Line AB:",ab
    pr2 "Line AC:",ac
    pr2 "Line BC:",bc
    pr2 "Left base:",hb
    pr2 "Height:",ht
    pr2 "Area:", ar
    pr1 ""
    '
    picklabel 0
    popstate
  'end if

  end procedure 'main

  EndScript

Frank Brübach

#10
Hey Charles and all... Thx for your Last example... Here however I have found my solution for moving Fonts...
I couldnt Rest to find this solution lol
  ' fonts are displayed and moving
  ' work in progress, by frank brübach, 18.10.2023, oxygenbasic
  '
  includepath "$\inc\"
  $ FileName "t.exe"
  'include  "RTL32.inc"
  'include  "RTL64.inc"
  $ title    "Rotating Triangle+moving fonts"
  $ fontA "Arial", FW_SEMIBOLD
  int width=640
  int height=480

  uses OpenglSceneFrame
  indexbase 1
  sys  texn[4]
  sys  GdiplusToken
  float ang1
  float li[16]
  float ma[13]
  sys cube pent
  dim Textrun as single
  dim cnt1 as single
  dim cnt2 as single

  sub Initialize(sys hWnd)
  '=======================
  end sub
  '
  sub Scene(sys hWnd)
  '==================
  '
  static single ra,ri,angi1=.5
  static int framerate
  static int textrun
  local bDone as long
  ' 
  '
  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
 
  static single ang1,angi1=1
  static single run
  '
  glClearColor 0.3, 0.3, 0.5, 0
  glClear GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT
  '
  '---------------------------------------------------- //
  do until bdone
 
  'text
  gldisable GL_LIGHTING
  glloadidentity
  static int framecount
  framecount++
  run++
  gltranslatef -.5, .35,-1.0
  glcolor3f .99, .50, .50
  glscalef .06, .06, .01
  gprint "frames: "+str(framecount)

  gltranslatef    0.0, -2.5, -1.0 '-4.0
  glrotatef ang1, 0.0, 0.0,  1.0
  '
  glBegin GL_TRIANGLES
  glColor3f  1.0, 0.0, 0.0 : glVertex3f  0.0,  2.0, 0.0
  glColor3f  0.0, 1.0, 0.0 : glVertex3f  -2.0, -2.0, 0.0
  glColor3f  0.0, 0.0, 1.0 : glVertex3f  2.0, -2.0, 0.0
  glEnd
'----------------------------------------------------------- //

  glloadidentity '2
  framecount++
  run++
  gltranslatef -.5, -.25,-1.0
  'glcolor3f .29, .50, .20
  glscalef .06, .06, .01
  gltranslatef    1.0, sin(0.0+run/100), -1.0 ' 'moving y-direction that's the solution ! :-)
  glColor3f 255,255,0
  gprint "gettickcounter: "+str(gettickcount/1000)

'----------------------------------------------------------- //
 
  glloadidentity '3
  framecount++
  run++
  gltranslatef -.5, -.25,-1.0
  glscalef .06, .06, .01
  gltranslatef sin(2.0+run/100), -1.0, -1.0 '-4.0 'moving x-direction
  glColor3f 0,255,200
  gprint "hello: "+str(framecount)

 
  'UPDATE ROTATION ANGLES
  '----------------------
  '
  bDone = true
  loop
   
  glDisable GL_BLEND

  ang1+=angi1
  if ang1>360 then ang1-=360
  '
  end sub


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

I did all in *.rar File below
And added a *.zip File

Charles Pegge


I have added color buttons. As you can see, these are quite easy to implement.

'#compact
 '%filename "t.exe"
 'uses RTL64
  % Title "Triangle Data:  Move points with mouse and arrow keys etc"

 '% WindowStyle WS_OVERLAPPEDWINDOW
 '% Animated
 '% ScaleUp
  % PlaceCentral
  % AnchorCentral

  % shaders

  uses consoleG
 'uses glo2/geoplanar
 
  'Keys: Esc, arrow-keys, n,m, F4

  BeginScript

  procedure sqbutton(float x,y)
  =============================
  glbegin GL_QUADS
  glvertex2f 0,0
  glvertex2f x,0
  glvertex2f x,y
  glvertex2f 0,y
  glend
  end procedure

  procedure main()
  ================

  'WaitForEvent '0 off 1 on (default on)
  static quad t1,t2

  static float rc,gc,bc 'colors

  if opening 'FIRST CALL ONLY
    timemark t1
    'picked=100
    'mbox "helo"
    'Triangle interior color
    rc=0.8
    gc=0.0
    bc=0.8
  end if
  '
  if closing 'FINAL CALL BEFORE SHUTDOWN
    'mbox "Bye!"
    exit sub
  end if
  cls
  shading
  UserMovement mu,1100,3 'symbol identity, count
  if opening
    mu[1].x= 0
    mu[1].y= 5
    mu[2].x=-5
    mu[2].y=-5
    mu[3].x= 5
    mu[3].y=-5
  endif
  scale 1
  picklabel 0
  int i
  for i=1 to 3
    pushstate
    color 1,.9,0,1
    mu[i].act
    scale 0.5
    go sphere
    popstate
  next
  picklabel 0
  float xa,xb,xc,ya,yb,yc
  xa=mu[1].x : ya=mu[1].y
  xb=mu[2].x : yb=mu[2].y
  xc=mu[3].x : yc=mu[3].y
  '
  select picked
    'COLOR BUTTON SELECTION
    case 10 : rc=0.9 : gc=0.2 : bc=0.0
    case 20 : rc=0.2 : gc=0.9 : bc=0.0
    case 30 : rc=0.0 : gc=0.6 : bc=0.9
    case 40 : rc=0.6 : gc=0.0 : bc=0.9
    'MOUSE DRAG ADJUSTMENT
    case 1100 : xa+=mu[1].d.x : ya+=mu[1].d.y
    case 1200 : xb+=mu[2].d.x : yb+=mu[2].d.y
    case 1300 : xc+=mu[3].d.x : yc+=mu[3].d.y
  end select
  flat
  thickness 2
  '
  if pick
    picklabel 2000
  else
    color 1,1,0,1
    pushstate
    move xa-.5,ya-1
    gprint "A"
    popstate
    pushstate
    move xb+1,yb+1
    gprint "B"
    popstate
    pushstate
    move xc-1,yc+1
    gprint "C"
    popstate
  endif
  '
  if not pick
    color rc,gc,bc
    float zp=-1.001
    glBegin GL_TRIANGLES
    glVertex3f xa,ya,zp
    glVertex3f xb,yb,zp
    glVertex3f xc,yc,zp
    glEnd
    '
    color 0,.9,.9
    glBegin GL_LINES
    glVertex2f xa,ya
    glVertex2f xb,yb
    glVertex2f xb,yb
    glVertex2f xc,yc
    glVertex2f xc,yc
    glVertex2f xa,ya
    glEnd
  endif

  move 5

  'if not pick
    if key[49] then picked=100 'keypress '1'
    if key[50] then picked=200 'keypress  '2'
    pushstate
    move -20,12
    static sys tally
    timemark t2
    scale 1.0
    '
    int dp=3
    '
    macro pr1(a) 'PRINTING LIST
    -----------------------------
      pushstate : color .5,1,1 : print a : popstate
      printl ""
    end macro
    '
    macro pr2(a,b) 'PRINTING LIST
    -----------------------------
      pushstate : color .5,1,1 : print a : popstate
      pushstate : color 1,1,.5 : move 4 : print str(b,dp) : popstate
      printl ""
    end macro
    '
    macro pr3(a,b,c) 'PRINTING LIST
    ------------------------------
      pushstate : color .5,1,1 : print a : popstate
      pushstate : color 1,1,.5 : move 4 : print str(b,dp) : popstate
      pushstate : color 1,1,.5 : move 8 : print str(c,dp) : popstate
      printl ""
    end macro
    '
    'BUTTON CONTROLS
    ----------------
    '
    pushstate
    if pick
      picklabel 10
    else
      color .80,.2,0
    endif
    sqbutton 2,2
    move 3.0
    '
    if pick
      picklabel 20
    else
      color .2,.80,0
    endif
    sqbutton 2,2
    move 3.0
    '
    if pick
      picklabel 30
    else
      color 0,.60,.90
    endif
    sqbutton 2,2
    move 3.0
    '
    if pick
      picklabel 40
    else
      color .60,0,.90
    endif
    sqbutton 2,2
    move 3.0
    '
    popstate

    move 0,-3.0,0
    '
    'DISPLAY INFO
    -------------
    picklabel 0

    pushstate
    scale 2
    color 1,1,1
    print "Triangle Data"
    popstate


    move 0,-1.5

   'pr2 "Action Code:   ", act
   'pr2 "indexbase      ", indexbase
   'pr2 "Keyboard Code: ", keyd
    pr2 "Picked ID:     ", picked
    '
    move 0,-1.5
    '
    pr3 "Point A: ", str(xa,3), ya
    pr3 "Point B: ", str(xb,3), yb
    pr3 "Point C: ", str(xc,3), yc
    '
    float ab,ac,bc,ar,ht,hb
    '
    ab=hypot(xa-xb, ya-yb)
    ac=hypot(xa-xc, ya-yc)
    bc=hypot(xb-xc, yb-yc)
    '
    hb=0.5* ( ab*ab - ac*ac + bc*bc ) / bc
    ht=sqr(ab*ab-hb*hb)
    ar=0.5*bc*ht

    'ANGLES
    float na,nb,nc
    nb=deg(asin(ht/ab))
    nc=deg(asin(ht/ac))
    na=180-nb-nc

    pr1 ""
    pr2 "Angle A:",na
    pr2 "Angle B:",nb
    pr2 "Angle C:",nc
   
    pr1 ""
    pr2 "Line AB:",ab
    pr2 "Line AC:",ac
    pr2 "Line BC:",bc
    pr2 "Left base:",hb
    pr2 "Height:",ht
    pr2 "Area:", ar
    pr1 ""
    '
    picklabel 0
    popstate
  'end if

  end procedure 'main

  EndScript

Frank Brübach

Thats an interesting example Charles thx :) do you have translated this example from another language?
Do you often use console OpenGL?
I only add a fifth color Button to understand the Triangel vector Data example

Regards Frank

Charles Pegge

ConsoleG is an extension of OpenglSceneFrame for console-like applications. Nearly all of these examples are originals, and have not been translated from other sources.

But my Opengl system is based on some NeHe lessons and various other sources including the wisdom of our late Mike Lobanovsky.

Opengl is very complicated and not very intuitive. It also evolves over time. So the best way to accumulate OpenGl ability is by adapting existing examples and tutorials.

Charles Pegge

This is a minimal example of line input:

  #compact
  % filename "t.exe"
 'uses RTL64
  % Title "Console Input Demo"
 '% Animated
  % ScaleUp
 '% PlaceCentral
 '% AnchorCentral
 '% NoEscape

  $ filename "t.exe"
 'uses RTL64
  uses ConsoleG

  procedure main()
  ================
  sys a,i,p
  static string ins
  static string s

  cls .10,.10,.20
  '
  'LINE INPUT
  '
  PushState
  color .20,.80,.00,.88
  Scale 2
  print "Enter: "
  color .80,.80,.00,.88
  a=input ins
  lastchar=0
  if a
    s=ins
    ins="" : cp=1
  endif
  PopState
  move 0,-5
  PushState
  scale 2
  printl s
  PopState
  lastkey=0
  lastchar=0
  '
  end procedure

  EndScript