Author Topic: OpenGL Basics  (Read 9672 times)

0 Members and 1 Guest are viewing this topic.

Arnold

  • Guest
Re: OpenGL Basics
« Reply #15 on: October 23, 2016, 01:23:17 PM »
Hi Charles,

I just saw your message and I must still check the link you indicated.

This is the current state of my experiments with the ConsoleG demo. I changed the behaviour of the arrow keys and n,m to start animation, F4 resets the values and F12 toggles between fullscreen and windowed mode. There are two problems though:

Code: OxygenBasic
  1. $ FileName "ConsoleGDemo.exe"
  2.  
  3. 'include "$/inc/RTL32.inc"
  4.  
  5.   % Title "ConsoleG Demo"
  6.   % Animated
  7.  '% ScaleUp
  8.  % PlaceCentral
  9.   % AnchorCentral
  10.    
  11.   % width 640
  12.   % height 480
  13.  
  14.   include "$\inc\ConsoleG.inc"
  15.  
  16.   'Keys: Esc, arrow-keys, n,m, F4
  17.  '      F12 toggles fullscreen and windowed mode
  18.  
  19.  
  20. 'screen dimensions
  21. int swidth  = GetSystemMetrics (SM_CXSCREEN)
  22. int sheight = GetSystemMetrics (SM_CYSCREEN)
  23. bool fullscreen=FALSE
  24.  
  25.  
  26.   BeginScript
  27.  
  28.   function WndMessages( hWndMain, wMsg, wParam, lparam ) as sys, link WndProcExtra
  29.   ============================================================================
  30.   'sys hWndMain in WinUtil.inc
  31.  'byte lastkey in WinUtil.inc
  32.  static int wleft, wtop, wwidth, wheight
  33.   RECT wrc
  34.  
  35.   select wMsg
  36.  
  37.   case WM_KEYUP    
  38.      if lastkey = 123 then 'F12
  39.       fullscreen = not fullscreen
  40.        if fullscreen then
  41.          GetWindowRect(hwndMain,@wrc)
  42.          wleft=wrc.left : wtop=wrc.top : wwidth=wrc.right-wrc.left : wheight=wrc.bottom-wrc.top          
  43.          SetWindowLong(hWndMain, GWL_STYLE, WS_POPUP)
  44.          MoveWindow(hWndMain,0,0,swidth,sheight,1)
  45.          ShowWindow(hWndMain, SW_RESTORE)
  46.          UpdateWindow(hWndMain)
  47.        else
  48.          SetWindowLong(hWndMain, GWL_STYLE, WS_OVERLAPPEDWINDOW)  
  49.          MoveWindow(hWndMain,wleft,wtop,wwidth,wheight,1)  
  50.          ShowWindow(hWndMain, SW_RESTORE)
  51.          UpdateWindow(hWndMain)
  52.        end if
  53.      end if
  54.   end select
  55.   end function
  56.  
  57.   sub main
  58.   ========
  59.   static float x,y,z
  60.   static float xspeed, yspeed, zspeed  
  61.  
  62.   pushstate
  63.   scale 2, 3
  64.   color 1,.5,0,1
  65.   print "Hello "
  66.  
  67.   scale 2, 1.25  
  68.   if key(VK_UP) then xspeed-=0.2
  69.   if key(VK_DOWN) then xspeed+=0.2
  70.   if key(VK_RIGHT) then yspeed-=0.2
  71.   if key(VK_LEFT) then yspeed+=0.2
  72.   if key(77) then zspeed-=0.2      'm,M
  73.  if key(78) then zspeed+=0.2      'n,N
  74.  if key(VK_F4) then x = y = z = xspeed = yspeed = zspeed = 0.0
  75.  
  76.   rotatex x : x+=xspeed : if abs(x)>360 then x=0
  77.   rotatey y : y+=yspeed : if abs(y)>360 then y=0
  78.   rotatez z : z+=zspeed : if abs(z)>360 then z=0
  79.  
  80.   print "World!"
  81.   popstate
  82.  
  83.   end sub 'main
  84.  
  85.   EndScript
  86.  

This will work for slow computers. For new fast computers the values for xspeed, yspeed and zspeed must be changed to 0.002 instead of 0.2. Unfortunately I still have not found out how to use timing but I think I will need it in some way.
It seems that I can only test F11 or F12 if I use lastkey to check the value. Is there another way to use e.g. F5?

Roland


.

Charles Pegge

  • Guest
Re: OpenGL Basics
« Reply #16 on: October 25, 2016, 12:08:01 AM »
You can use any number of keys (depending on fingers and nose :) ) simultaneously. The VK_SHIFT key is useful for fast movement.

Here is a macro from consoleG.inc, which is used to control moveable objects with the keyboard.

Code: [Select]
  macro MoveThisWithKeys(mv,an,k)
  ===============================
  if key[VK_CONTROL]
    if key[37] then a.y-=an : k=2  ' left
    if key[39] then a.y+=an : k=2  ' right
    if key[38] then a.x-=an : k=2  ' up
    if key[40] then a.x+=an : k=2  ' down
    if key[33] then a.z+=an : k=2  ' PgUp
    if key[34] then a.z-=an : k=2  ' PgDn
    if key[36]
      a.x=0. : a.y=0. : a.z=0. : k=3 'HOME'
    end if
    static float m
    m=1.0+m*.01
    if key[0xbd] then s.x/=m : s.y/=m : s.z/=m : k=1  ' -
    if key[0xbb] then s.x*=m : s.y*=m : s.z*=m : k=1  ' =
  else
    scope
    static float m
    if key[VK_SHIFT] then m=mv*3 else m=mv
    if key[37] then p.x-=m : k=1  ' left
    if key[39] then p.x+=m : k=1  ' right
    if key[38] then p.y+=m : k=1  ' up
    if key[40] then p.y-=m : k=1  ' down
    if key[33] then p.z-=m : k=1  ' PgUp
    if key[34] then p.z+=m : k=1  ' PgDn
    '
  end if
  end scope
  end macro

Arnold

  • Guest
Re: OpenGL Basics
« Reply #17 on: October 28, 2016, 12:29:22 AM »
Hi Charles,

I assume the macro above (and MoveThisWithMouse) can be used generally for moving things around and also as a pattern for similar actions? I used the part for increasing / decreasing speed faster.
My purpose for enhancing your little demo was to check what could be done with WndProcExtra and how to add some events.
Although I am far away from understanding all the tools you provided for OpenGl the ConsoleG demo works already very nice in my opinion. It will be interesting to investigate in some more areas. For instance using ImgWin.inc and perhaps adding some user functions it should already be possible to write NeHe lessons 1 - 20 using the provided tools of OxygenBasic.

Roland

Code: [Select]
$ FileName "ConsoleGDemo.exe"

'include "$/inc/RTL32.inc"

  % Title "ConsoleG Demo - F1 for Help"
  % Animated
 '% ScaleUp
  % PlaceCentral
  % AnchorCentral
   
  % width 640
  % height 480
 
  include "$\inc\ConsoleG.inc"
 
  'Keys: Esc, arrow-keys, n,m, F4, +,-
  '      F12 toggles fullscreen and windowed mode


'screen dimensions
int swidth  = GetSystemMetrics (SM_CXSCREEN)
int sheight = GetSystemMetrics (SM_CYSCREEN)
bool fullscreen=FALSE

  BeginScript

  sub main
  ========
  static float x,y,z
  static float xspeed, yspeed, zspeed
  static float m
  static int wleft, wtop, wwidth, wheight
  RECT wrc

  'F1 HELP
  '
  if key[0x70]
    pushstate
    move 5,14
    color 1,.8,.5
    scale  1.5,1.0
    printl "Active Keys:"
    scale  1/1.5,1.0
    printl
    printl "ALT-F4, ESC - Exit"
    printl "F12 - Toggle Fullscreen"
    printl "Arrow Keys, N, M: "
    printl "Start moving and"
    printl "   increase or decrease speed"
    printl "+ increase move with faster speed"
    printl "- decrease move with faster speed"
    printl "F4 - Stop and reset values"
    printl "F1 - This help"
    printl
    popstate
  end if
  '
  lastkey=0
  lastchar=0

  pushstate
  scale 2, 3
  color 1,.5,0,1
  print "Hello "
 
  scale 2, 1.25   
  if key(VK_UP) then key(VK_UP)=FALSE : xspeed-=0.01
  if key(VK_DOWN) then key(VK_DOWN)=FALSE : xspeed+=0.01
  if key(VK_RIGHT) then key(VK_RIGHT)=FALSE : yspeed-=0.01
  if key(VK_LEFT) then key(VK_LEFT)=FALSE : yspeed+=0.01
  if key(77) then key(77)=FALSE : zspeed-=0.01      'm,M
  if key(78) then key(78)=FALSE : zspeed+=0.01      'n,N
  if key(VK_F4) then x = y = z = xspeed = yspeed = zspeed = 0.0

  if key(VK_ADD) or key(187) then       '+
    key(VK_ADD) = FALSE : key(187)=FALSE
    m=1.0+m*.1
    xspeed*=m : yspeed*=m : zspeed*=m
  end if
  if key(VK_SUBTRACT) or key(189) then  '-
    key(VK_SUBTRACT)=FALSE: key(189)=FALSE
    xspeed/=m : yspeed/=m : zspeed/=m
  end if

  if key(VK_F12) then
    key(VK_F12) = FALSE
    fullscreen = not fullscreen
    if fullscreen then
      GetWindowRect(hwndMain,@wrc)
      wleft=wrc.left : wtop=wrc.top : wwidth=wrc.right-wrc.left : wheight=wrc.bottom-wrc.top           
      SetWindowLong(hWndMain, GWL_STYLE, WS_POPUP)
      MoveWindow(hWndMain,0,0,swidth,sheight,1)
      ShowWindow(hWndMain, SW_RESTORE)
    else
      SetWindowLong(hWndMain, GWL_STYLE, WS_OVERLAPPEDWINDOW)   
      MoveWindow(hWndMain,wleft,wtop,wwidth,wheight,1)   
      ShowWindow(hWndMain, SW_RESTORE)
    end if
  end if
 
  rotatex x : x+=xspeed : if x>=360 then x-=360 : if x<=0 then x+=360
  rotatey y : y+=yspeed : if y>=360 then y-=360 : if y<=0 then y+=360
  rotatez z : z+=zspeed : if z>=360 then z-=360 : if z<=0 then z+=360
 
  print "World!"
  popstate

  end sub 'main

  EndScript


   

.

Charles Pegge

  • Guest
Re: OpenGL Basics
« Reply #18 on: October 28, 2016, 02:18:29 AM »
Hi Roland,

MoveThisWithMouse is used by the moveableObject class, managing specific variables.

PineCone.o2bas and MoveableObj.o2bas demonstrate how this class is used.

But I am adding a few more tricks to ConsoleG:

In a single line of code, UserMovement will allow you to move any piece of geometry or text, like so:

Code: [Select]
  pushstate
  color 1,.5,0,1
  UserMovement m1,100 'identity in steps of 100
  scale 2, 3
  print "Hello "
  popstate
  move 5

  pushstate
  color 1,1,0,1
  UserMovement m2,200
  scale 4
  print "World"
  popstate

I have also added some timer and time keeping functions for precise management of events, independend of the frame rate or the windows WM_timer.

Will post soon but it's hard to know when to stop :)

Arnold

  • Guest
Re: OpenGL Basics - ConsoleCommand
« Reply #19 on: October 28, 2016, 05:05:43 AM »
Hi Charles,

I refer to projectsA\OpenglCns\ConsoleComand.o2bas. If I try to run the example there is an error message in line 18 (WaitForMultipleObjects). If I comment out line 18 or use line 18 this way:

WaitForMultipleObjects 1,@infp.hthread, '1,-1

the program would run in some way but I am not sure if this is correct. You used WaitForMultipleObjects in some other demos and there is no problem in these cases. I also noticed that not all ansi characters are shown correctly e.g. the Umlauts like Ä,ä, Ü,ü, Ö,ö. etc.
Is there a reason why WaitForMultipleObjects does not work correctly in this special case? The program does work with a previous version of Oxygen, maybe it works with Oxygen in progress too? BTW the demo calls cmd.exe which if called separately will show the text properly.

Roland

PS: I tested PineCone.o2bas and MoveableObj.o2bas. Using keys, mouse buttons and wheel work perfectly on my system. It is amazing to see how much is possible with comparatively few lines of code.


.

Charles Pegge

  • Guest
Re: OpenGL Basics
« Reply #20 on: October 28, 2016, 08:29:09 AM »
Hi Roland,

I'm using ANSI_CHARSET. Could that be the problem for the missing accented characters?

from openglsceneframe.inc
Code: [Select]
  sub BuildFont (sys hWnd,hDC,hRC, string name, sys weight, base)
  ===============================================================
  indexbase 0
  LOGFONT   glFont
  sys       glFontHandle
  '
  glFont.lfHeight         = 1                             'Height Of Font
  glFont.lfWeight         = weight                        'Font Weight FW_BOLD etc
  glFont.lfCharSet        = ANSI_CHARSET                  'Character Set Identifier
  glFont.lfOutPrecision   = OUT_TT_PRECIS                 'Output Precision
  glFont.lfClipPrecision  = CLIP_DEFAULT_PRECIS           'Clipping Precision
  glFont.lfQuality        = ANTIALIASED_QUALITY           'Output Quality
  glFont.lfPitchAndFamily = FF_DONTCARE or DEFAULT_PITCH  'Family And Pitch
  glFont.lfFaceName       = name    ' "Arial" "Lucida Console" "Consolas" ' "Courier New"    'Font Name
  '
  glFontHandle = CreateFontIndirect(@glFont)
  glFontHandle = SelectObject(hDC, glFontHandle)
  wglUseFontOutlinesA (hDC, 0, 256, base, 0.0, .25, WGL_FONT_POLYGONS, @gmf[base-1024])
  DeleteObject(glFontHandle)
  end sub

Arnold

  • Guest
Re: OpenGL Basics
« Reply #21 on: October 28, 2016, 11:01:35 AM »
Hi Charles,

Nehe lesson 14 builds the fonts almost the same way and I have no problems. Also not in ConsoleText.o2bas when entering text.
But I noticed that the output of the command is saved to temp.txt and here the special chars are saved differently too. So I tried in a console window:
help > tmp.txt
and voila - tmp.txt shows the same output as temp.txt. So nothing is wrong with Oxygenbasic. Maybe I must add an additional driver for the saving purpose, but this is not worthwhile for this old system.

Roland

Charles Pegge

  • Guest
Re: OpenGL Basics
« Reply #22 on: November 01, 2016, 03:18:53 AM »
Hi Roland,

This is the ANSI character set depicted thru OpenGl. As you can see, there are a few missing characters in the upper range.

.

Arnold

  • Guest
Re: OpenGL Basics
« Reply #23 on: November 01, 2016, 05:53:00 AM »
Hi Charles,

actually this was my fault. I did not realize at once that CommandConsole.o2bas redirects the output to temp.txt which does not work fully with cmd.exe, even not in Windows 10. It would work with powershell.exe though. If I open temp.txt with the windows editor, some special characters are shown differently, but if I use in a console window the command: type temp.txt these special chars are displayed correctly too (strange). I tried to change to some different codepages using chcp.exe but the results were the same. Probably this is a strange historical caused behaviour of Dos / Windows.
The BuildFont procedure itself should work correctly. I can test this with ConsoleText.o2bas in folder OpenglCns. When I enter text in the input field the characters are displayed correctly.

The function WaitForMultipleObjects in ConsoleCommand.o2bas is more interesting. There was no error reported using A41 26/07/2015. Will it work for Oxygen in progress too?

Roland


Charles Pegge

  • Guest
Re: OpenGL Basics
« Reply #24 on: November 02, 2016, 09:36:56 AM »

Hi Roland,

I have not seen any problems with WaitForMultipleObjects. I have been checking for subtle syntax glitches though.

I want to include a few more examples before releasing:

ControlPanelArray: (where OOP becomes a necessity)



.