Author Topic: Opengl Console  (Read 6162 times)

0 Members and 1 Guest are viewing this topic.

Charles Pegge

  • Guest
Opengl Console
« on: March 03, 2014, 05:17:21 PM »




Easy code for console-based applications.

Code: [Select]
  includepath "$\inc\"
  include "ConsoleG.inc"

  sub main()
  ==========
  string s
  title  "glConsole Hello World"
  cls
  printl "Hello"
  printl "World"
  sys i
  for i=1 to 10
    s= i tab chr(i+64) tab hex(i+64,2)+"h"
    printl s,1
  next
  color .20,.80,.00,.88
  scale 2,2
  printl ""
  outputinput("Enter: ")
  scale .5,.5
  color .00,.80,.80,1.
  if LastInput
    printl "Last input: " LastInput,1 'font B
  end if
  printl ""
  '
  shading 'opposite of 'flat'
  color .99,.80,.00,.99
  GoldMaterial.act
  gltranslatef 2.,-2.,-1.0
  go sphere
  glTranslatef 0.,-2.0,0.
  RedMaterial.act
  go cube
  glTranslatef 2.00,.00,.00
  glrotatef -70,1,0,0
  glscalef 4,4,4
  color .70,.70,.20,.99
  print3d "Solids",1,0
 
  end sub

Charles Pegge

  • Guest
Re: Opengl Console
« Reply #1 on: March 05, 2014, 09:24:18 AM »



Further developments adding move rotate line point linewidth pointsize pushstate popstate

Code: [Select]
  % Title "Console Demo"
  % Animated
 '% ScaleUp
 '% PlaceCentral
 '% AnchorCentral
  includepath "$\inc\"
  include "ConsoleG.inc"

  ! Craft


  sub main
  ========
  string s
  cls .0,.0,.0,0.
  scale 2.,1.25
  printl "Hello World"
  scale .5,.80
  sys i
  for i=1 to 10
    PushState
    color .99,.00,.00
    print i
    PopState
    s= tab chr(i+64) tab hex(i+64,2)+"h"
    printl s
  next
  printl
  printl
  PushState
  color .20,.80,.00,.88
  Scale 2
  print "Enter: "
  color .80,.80,.00,.88
  input(1) '1: using font B
  PopState
  printl
  color .00,.80,.80,1.
  thickness 3
  line 10
  PointSize 11
  point 10
  move 0,-1
  if LastInput
    printl "Last input: " LastInput,0 'font A
  end if
  printl
  '
  shading 'opposite of 'flat'
  GoldMaterial.act
  gltranslatef 2.,-2.,-1.0
  GoldMaterial.act
  go sphere
  glTranslatef 0.,-2.0,0.
  RedMaterial.act
  go cube
  pushState
  move 2.00
  rotateX -70
  scale 5
  'color .70,.70,.20,.99
  SilverMaterial.act
  print3d "Solids",1,0
  popstate
  move 0.,-5.,-4.0
  pushstate
  static float ang
  rotateY ang
  craft
  popstate
  ang+=.5 : if ang>=360 then ang-=360
  end sub 'main

  sub Craft
  =========
  '
  'CRAFT MAIN BODY
  '
  PickLabel 1
  '
  glPushMatrix
  'glTranslatef t.p.x+dx,t.p.y+dy,t.p.z+dz
  'glRotatef    t.a.x,1,0,0
  'glRotatef    t.a.y,0,1,0
  'glRotatef    t.a.z,0,0,1
  glScalef      3.,.5,3.
  SilverMaterial.act
  glCallList sphere
  '
  'FINS
  '
  for i=0 to 5
  glpushMatrix
  glRotatef i*60.0,0,1,0
  glTranslatef -.5,.20,.0
  glScalef      .4,.89,.15
  glCallList sphere
  glPopMatrix
  next
  '
  'THRUSTERS
  '
  for i=0 to 5
  glpushMatrix
  glRotatef i*60.0,0,1,0
  glTranslatef -.75,-.60,.00
  glScalef      .10, .30,.10
  glCallList sphere
  glPopMatrix
  next
  '
  'CABIN
  '
  glTranslatef .00,.99,.00
  glScalef     .50,1.99,.50
  AlloyMaterial.act
  glCallList sphere
  '
  'PORTS
  '
  for i=0 to 5
  glpushMatrix
  glRotatef 30.0+i*60.0,0,1,0
  glTranslatef .90,.10,.00
  BlackShinyMaterial.act
  glscalef .10,.40,.20
  glCallList sphere
  glPopMatrix
  next
  '
  glPopMatrix 'end of craft main body

  end sub 'craft

Charles Pegge

  • Guest
Re: Opengl Console
« Reply #2 on: March 05, 2014, 01:53:25 PM »

Added Arc, Fan and Grid



Code: [Select]
  % Title "Console Demo"
 '% Animated
  % ScaleUp
 '% PlaceCentral
 '% AnchorCentral
  includepath "$\inc\"
  include "ConsoleG.inc"

  sub main
  ========
  cls
  pushstate
    move 5,-6
    color .50,.00,.70,1. : fan 5.,000,060,2 'wedge
    color .40,.50,.00,1. : fan 5.,060,120,2 'wedge
    color 1,1,0,1
    move .0,.0,.0001
    color .00,.00,.30,.5 : fan 3.,000,360,2 'transp overlay
    thickness 2
    color .90,.20,.00,.5 : arc 5,0,120,1
    move .0,-12.0,.0001
    thickness 1
    color .0,.5,.7,1
    grid 1.,20,10 'fine grid
    thickness 3
    move .0,.0,.0001
    grid 1.,20,10,5 'thick grid
  popstate
  move 0,-.5
  scale 2
  printl "2D Graphics"
  'static float ang
  'ang+=.5 : if ang>=360 then ang-=360
  end sub 'main


Charles Pegge

  • Guest
Re: Opengl Console
« Reply #3 on: March 05, 2014, 04:26:08 PM »

Added Texture, LoadTexture to the above example



Code: [Select]
  % Title "Console Demo"
 '% Animated
  % ScaleUp
 '% PlaceCentral
 '% AnchorCentral
  includepath "$\inc\"
  include "ConsoleG.inc"

  sub main
  ========
  static sys   imgn,res,wi,ht
  if not imgn
    imgn=21
    res=512
    LoadTexture "../images/Dawn1815.jpg",imgn,res,wi,ht
  end if
  cls
  pushstate
    move 5,-6
    color .50,.00,.70,1. : fan 5.,000,060,2 'wedge
    color .40,.50,.00,1. : fan 5.,060,120,2 'wedge
    color 1,1,0,1
    move .0,.0,.0001
    color .00,.00,.30,.5 : fan 3.,000,360,2 'transp overlay
    thickness 2
    color .90,.20,.00,.5 : arc 5,0,120,1
    move .0,-12.0,.0001
    '
    'display image
    '
    pushstate
      move 4
      flat : color 1,1,1,1
      texture imgn
      quadnorm 8.0,7.0 'apply image texture to quad
      texture 0
    popstate
    move 0,0,.0001
    thickness 1
    color .0,.5,.7,1
    grid 1.,20,10 'fine grid
    thickness 3
    move .0,.0,.0001
    grid 1.,20,10,5 'thick grid
  popstate
  move 0,-.5
  scale 2
  printl "2D Graphics"
  'static float ang
  'ang+=.5 : if ang>=360 then ang-=360
  end sub 'main



jack

  • Guest
Re: Opengl Console
« Reply #4 on: March 06, 2014, 03:22:34 PM »
thank you Charles, these are really cool examples.   :)

Charles Pegge

  • Guest
Re: Opengl Console
« Reply #5 on: March 07, 2014, 01:46:15 PM »

Adding some user-interface:

This is much easier and more fun than coding  Windows GUI. It is the 1980's revisited :)



examples/opengl/Console10.o2bas

32-bit binary demo:


.

JRS

  • Guest
Re: Opengl Console
« Reply #6 on: March 07, 2014, 02:04:16 PM »
Quote
This is much easier and more fun than coding Windows GUI.

Anything is more fun than coding using the winapi.