Author Topic: How to size the window in OpenGL  (Read 4486 times)

0 Members and 1 Guest are viewing this topic.

chrisc

  • Guest
How to size the window in OpenGL
« on: April 14, 2018, 06:24:00 PM »
Hello
i have modified the QuadRotate.o2bas  to become QuadRotate2.o2bas

it is displaying well but i find that the display window size is too big,  i need to resize it to
a smaller size of say  300 x 300 pixels

How to do that ?
Code: [Select]
  includepath "$\inc\"
  $ FileName  "QuadRotate2.exe"
  'include    "RTL32.inc"
  include    "RTL64.inc"
 

  $ title     "Rotating Quad2"
  include     "OpenglSceneFrame.inc"
 


'  Note that we must specify exactly these equates
'  all in uppercase ,  otherwise it can results in compilation errors
#define GL_TRIANGLES        0x0004
#define GL_TRIANGLE_FAN 0x0006
#define GL_QUAD_STRIP     0x0008



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




  sub scene(sys hWnd)
  '==================
  '
  static single s1,s2,s3,s4,ang1
 ActiveFrame

'  increase this angle for faster rotation between 1 and 10
   angi1=1
  '
  glLoadIdentity
  glClear GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT

 '  Greenish Beige background color
   glClearColor .91,.94,.82,1
  '
  '
  s1=.2    'x y
  s2=-1    'z
  s3=0.5   'color
  s4=s3*.2 'color
  '
  glrotatef ang1, 0,0,1


  '
'   original square -- this work
' glbegin GL_QUADS
' glcolor4f   00,  s3,  s3, 1 : glvertex3f -s1, -s1,  s2
 ' glcolor4f   s3,  s3,  00, 1 : glvertex3f  s1, -s1,  s2
 ' glcolor4f   s4,   0,  s3, 1 : glvertex3f  s1,  s1,  s2
'  glcolor4f   s4,   0,  s3, 1 : glvertex3f -s1,  s1,  s2
'  glend


'   semi triangle  -- this work
'  glBegin  GL_TRIANGLE_FAN
   '     glcolor4f   00,  s3,  s3, 1  : glvertex3f  -s1, -s1,  s2   '1st triangle
   '      glcolor4f   s3,  s3,  00, 1 : glvertex3f  s1, -s1,  s2
   '      glcolor4f   s4,   0,  s3, 1  :  glvertex3f  -.3,-.1,  s2
   '      glcolor4f   s4,   0,  s3, 1  :  glvertex3f  s1,  s1 ,  -s2   '2nd
    '      glcolor4f   00,  s3,  s3, 1 : glvertex3f  s1,  -s1,  s2   '3rd
   '       glcolor4f   00,  s3,  s3, 1 : glvertex3f  s1,  s1,  -s2      '4th
  '   glEnd

 '  Triangle  -- this work
'   ensure that  z = -1.  thru' out
 '  glBegin GL_TRIANGLES 
'       glColor3f 1.0, 0.0, 0.0 :   glVertex3f   0.0,  .3,-1.
'       glColor3f 0.0, 1.0, 0.0 :   glVertex3f  0.2, -0.1,-1.
'       glColor3f 0.0, 0.0, 1.0 :   glVertex3f  -0.2,-0.1,-1.
' glEnd


'  Triangle  -- this work
'   this place triangle off center and if we increase the  -ve z
'   the object gets smaller and will spin at a distance of 0.8 from the center
 '   glTranslatef .80, 0.0, -2.0
  ' glBegin GL_TRIANGLES
'  glColor3f 1.0, 0.0, 0.0 : glVertex3f 0.0,  .30,-1.0
'  glColor3f 0.0, 1.0, 0.0 : glVertex3f 0.26,-0.15,-1.0
 ' glColor3f 0.0, 0.0, 1.0 : glVertex3f-0.26,-0.15,-1.0
'  glEnd

'  this work
' Half red square rotated off center
'   glTranslatef 2.40,0.0,-10.0
'   glBegin(GL_QUADS)
'  glColor3f   1.0, 0.0, 1.0
'  glVertex3f -1.0,-1.0, 0.0
'  glColor3f   1.0, 1.0, 1.0
'  glVertex3f  1.0,-1.0, 0.0
'  glVertex3f  1.0, 1.0, 0.0
'  glColor3f   1.0, 1.0, 1.0
'  glVertex3f -1.0, 1.0, 0.0
'  glEnd


'  rotating  off center Cube  -- this work
 ' glTranslatef -2.0, -2.0, -12.0
 ' glBegin GL_QUADS
 ' glColor3f   0.0, 1.0, 0.0
 ' glVertex3f  1.0, 1.0,-1.0
 ' glVertex3f -1.0, 1.0,-1.0
'  glVertex3f -1.0, 1.0, 1.0
 ' glVertex3f  1.0, 1.0, 1.0
 ' glColor3f   1.0, 0.5, 0.0
 ' glVertex3f  1.0,-1.0, 1.0
 ' glVertex3f -1.0,-1.0, 1.0
 ' glVertex3f -1.0,-1.0,-1.0
 ' glVertex3f  1.0,-1.0,-1.0
 ' glColor3f   1.0, 0.0, 0.0
'  glVertex3f  1.0, 1.0, 1.0
 ' glVertex3f -1.0, 1.0, 1.0
 ' glVertex3f -1.0,-1.0, 1.0
 ' glVertex3f  1.0,-1.0, 1.0
  'glColor3f   1.0, 1.0, 0.0
 ' glVertex3f  1.0,-1.0,-1.0
 ' glVertex3f -1.0,-1.0,-1.0
 ' glVertex3f -1.0, 1.0,-1.0
 ' glVertex3f  1.0, 1.0,-1.0
  'glColor3f   0.0, 0.0, 1.0
 ' glVertex3f -1.0, 1.0, 1.0
 ' glVertex3f -1.0, 1.0,-1.0
 ' glVertex3f -1.0,-1.0,-1.0
 ' glVertex3f -1.0,-1.0, 1.0
' glColor3f  1.0, 0.0, 1.0
 ' glVertex3f 1.0, 1.0,-1.0
 ' glVertex3f 1.0, 1.0, 1.0
 ' glVertex3f 1.0,-1.0, 1.0
'  glVertex3f 1.0,-1.0,-1.0
' glEnd
 

' DrawDiamond   -- this work  very well
  '  glTranslatef 1.4,0.0,-5.0
  '    glbegin GL_TRIANGLE_FAN  'top part
  '        glcolor3ub 255,   0,   0 : glvertex3f  0, 1.414, 0
   '       glcolor3ub   0, 255,   0 : glvertex3f  1, 0, 1
    '      glcolor3ub   0,   0, 255 : glvertex3f  1, 0,-1
    '      glcolor3ub   0, 255,   0 : glvertex3f -1, 0,-1
   '       glcolor3ub   0,   0, 255 : glvertex3f -1, 0, 1
   '       glcolor3ub   0, 255,   0 : glvertex3f  1, 0, 1
  '     glend
   '    glbegin GL_TRIANGLE_FAN    'bottom part
    '      glcolor3ub 255,   0,   0 : glvertex3f  0,-1.414, 0
     '     glcolor3ub   0, 255,   0 : glvertex3f  1, 0, 1
    '      glcolor3ub   0,   0, 255 : glvertex3f -1, 0, 1
      '    glcolor3ub   0, 255,   0 : glvertex3f -1, 0,-1
     '     glcolor3ub   0,   0, 255 : glvertex3f  1, 0,-1
      '    glcolor3ub   0, 255,   0 : glvertex3f  1, 0, 1
    '   glend



    'draws a 3D cube object  -- drawcube  works
       glTranslatef 1.4,0.0,-5.0
      glBegin  GL_QUADS
        glRotatef  ang1, 1.0, 1.0, 1.0         ' Rotate the quad on the X axis
       glcolor3ub 255,0,0
       glVertex3f  0.5,  0.5, -0.5    ' Top right of the quad (Top)
       glVertex3f -0.5,  0.5, -0.5    ' Top left of the quad (Top)
       glVertex3f -0.5,  0.5,  0.5    ' Bottom left of the quad (Top)
       glVertex3f  0.5,  0.5,  0.5    ' Bottom right of the quad (Top)

       glcolor3ub 255,255,0
       glVertex3f  0.5, -0.5,  0.5    ' Top right of the quad (Bottom)
       glVertex3f -0.5, -0.5,  0.5    ' Top left of the quad (Bottom)
       glVertex3f -0.5, -0.5, -0.5    ' Bottom left of the quad (Bottom)
       glVertex3f  0.5, -0.5, -0.5    ' Bottom right of the quad (Bottom)

       glcolor3ub 255,0,255
       glVertex3f  0.5,  0.5,  0.5    ' Top right of the quad (Front)
       glVertex3f -0.5,  0.5,  0.5    ' Top left of the quad (Front)
       glVertex3f -0.5, -0.5,  0.5    ' Bottom left of the quad (Front)
       glVertex3f  0.5, -0.5,  0.5    ' Bottom right of the quad (Front)

       glcolor3ub 0,0,255
       glVertex3f  0.5, -0.5, -0.5    ' Top right of the quad (Back)
       glVertex3f -0.5, -0.5, -0.5    ' Top left of the quad (Back)
       glVertex3f -0.5,  0.5, -0.5    ' Bottom left of the quad (Back)
       glVertex3f  0.5,  0.5, -0.5    ' Bottom right of the quad (Back)

       glcolor3ub 0,255,255
       glVertex3f -0.5,  0.5,  0.5    ' Top right of the quad (Left)
       glVertex3f -0.5,  0.5, -0.5    ' Top left of the quad (Left)
       glVertex3f -0.5, -0.5, -0.5    ' Bottom left of the quad (Left)
       glVertex3f -0.5, -0.5,  0.5    ' Bottom right of the quad (Left)

       glcolor3ub 255,128,0
       glVertex3f  0.5,  0.5, -0.5    ' Top right of the quad (Right)
       glVertex3f  0.5,  0.5,  0.5    ' Top left of the quad (Right)
       glVertex3f  0.5, -0.5,  0.5    ' Bottom left of the quad (Right)
       glVertex3f  0.5, -0.5, -0.5    ' Bottom right of the quad (Right)
    glEnd
   
  sleep (2)

   glLoadIdentity
      glTranslatef 1.5, 0.0, -7.0            ' Move right 1.5 units and into the screen
      glRotatef  ang1, 1.0, 1.0, 1.0         ' Rotate the quad on the X axis
      glBegin  GL_QUADS
         glColor3f   0.0,  1.0,  0.0         ' Set the color to green
         glVertex3f  1.0,  1.0, -1.0         ' Top right of the quad (Top)
         glVertex3f -1.0,  1.0, -1.0         ' Top left of the quad (Top)
         glVertex3f -1.0,  1.0,  1.0         ' Bottom left of the quad (Top)
         glVertex3f  1.0,  1.0,  1.0         ' Bottom right of the quad (Top)

         glColor3f   1.0,  0.5,  0.0         ' Set the color to orange
         glVertex3f  1.0, -1.0,  1.0         ' Top right of the quad (Bottom)
         glVertex3f -1.0, -1.0,  1.0         ' Top left of the quad (Bottom)
         glVertex3f -1.0, -1.0, -1.0         ' Bottom left of the quad (Bottom)
         glVertex3f  1.0, -1.0, -1.0         ' Bottom right of the quad (Bottom)

         glColor3f   1.0,  0.0,  0.0         ' Set the color to red
         glVertex3f  1.0,  1.0,  1.0         ' Top right of the quad (Front)
         glVertex3f -1.0,  1.0,  1.0         ' Top left of the quad (Front)
         glVertex3f -1.0, -1.0,  1.0         ' Bottom left of the quad (Front)
         glVertex3f  1.0, -1.0,  1.0         ' Bottom right of the quad (Front)

         glColor3f   1.0,  1.0,  0.0         ' Set the color to yellow
         glVertex3f  1.0, -1.0, -1.0         ' Top right of the quad (Back)
         glVertex3f -1.0, -1.0, -1.0         ' Top left of the quad (Back)
         glVertex3f -1.0,  1.0, -1.0         ' Bottom left of the quad (Back)
         glVertex3f  1.0,  1.0, -1.0         ' Bottom right of the quad (Back)

         glColor3f   0.0,  0.0,  1.0         ' Set the color to blue
         glVertex3f -1.0,  1.0,  1.0         ' Top right of the quad (Left)
         glVertex3f -1.0,  1.0, -1.0         ' Top left of the quad (Left)
         glVertex3f -1.0, -1.0, -1.0         ' Bottom left of the quad (Left)
         glVertex3f -1.0, -1.0,  1.0         ' Bottom right of the quad (Left)

         glColor3f   1.0,  0.0,  1.0         ' Set the color to violet
         glVertex3f  1.0,  1.0, -1.0         ' Top right of the quad (Right)
         glVertex3f  1.0,  1.0,  1.0         ' Top left of the quad (Right)
         glVertex3f  1.0, -1.0,  1.0         ' Bottom left of the quad (Right)
         glVertex3f  1.0, -1.0, -1.0         ' Bottom right of the quad (Right)
      glEnd


   sleep (2)
 '   draw the pyramid using triangles
 ' // Reset the view
      glLoadIdentity

      glTranslatef -1.5, 0.0, -6.0           ' Move left 1.5 units and into the screen
      glRotatef  ang1, 0.0, 1.0, 0.0          ' Rotate the triangle on the Y axis

      glBegin %GL_TRIANGLES
         ' Front
         glColor3f   1.0,  0.0,  0.0         ' Red
         glVertex3f  0.0,  1.0,  0.0         ' Top of triangle (Front)
         glColor3f   0.0,  1.0,  0.0         ' Green
         glVertex3f -1.0, -1.0,  1.0         ' Left of triangle (Front)
         glColor3f   0.0,  0.0,  1.0         ' Blue
         glVertex3f  1.0, -1.0,  1.0         ' Right of triangle (Front)

         ' Right
         glColor3f   1.0,  0.0,  0.0         ' Red
         glVertex3f  0.0,  1.0,  0.0         ' Top of triangle (Right)
         glColor3f   0.0,  0.0,  1.0         ' Blue
         glVertex3f  1.0, -1.0,  1.0         ' Left of triangle (Right)
         glColor3f   0.0,  1.0,  0.0         ' Green
         glVertex3f  1.0, -1.0, -1.0         ' Right of triangle (Right)

         ' Back
         glColor3f   1.0,  0.0,  0.0         ' Red
         glVertex3f  0.0,  1.0,  0.0         ' Top of triangle (Back)
         glColor3f   0.0,  1.0,  0.0         ' Green
         glVertex3f  1.0, -1.0, -1.0         ' Left of triangle (Back)
         glColor3f   0.0,  0.0,  1.0         ' Blue
         glVertex3f -1.0, -1.0, -1.0         ' Right of triangle (Back)

         ' Left
         glColor3f   1.0,  0.0,  0.0         ' Red
         glVertex3f  0.0,  1.0,  0.0         ' Top of triangle (Left)
         glColor3f   0.0,  0.0,  1.0         ' Blue
         glVertex3f -1.0, -1.0, -1.0         ' Left of triangle (Left)
         glColor3f   0.0,  1.0,  0.0         ' Green
         glVertex3f -1.0, -1.0,  1.0         ' Right of triangle (Left)
      glEnd

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


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








chrisc

  • Guest
Re: How to size the window in OpenGL
« Reply #1 on: April 15, 2018, 07:19:36 AM »
Hello Charles

i found a way to resize the window by modifying the include file OpenglSceneFrame.inc
to a custom made  OpenglSceneFrameSpQ.inc 

by modifying the code at

Code: [Select]
' OpenglSceneFrameSpQ.inc
' This is custom made for the Quad Rotate2 with the frame size

 'CONDITIONAL/DEFAULT EQUATES
  ' custom made for cubic sphere
  %% title  "OpenGl Scene"
  %% width  300
  %% height 300
  %% keydown
  '
  #ifndef ExplicitMain
  MainWindow     width,height,%WS_POPUP
  #endif

so that the window size is  now 300 ,300 

Now the window size is okay  but  i can't  center this window because
MainWindow ( sys, sys, sys)   function accepts  only 3 parameters   

the new question is how to center this window on the screen ?

currently the window is located at the top left corner of the screen.






Mike Lobanovsky

  • Guest
Re: How to size the window in OpenGL
« Reply #2 on: April 15, 2018, 07:53:33 AM »
Since you've already started to modify the include files, proceed as follows:
  • use the SystemParametersInfo() API with SPI_GETWORKAREA to determine the current full screen sizes not obscured by the tray;
  • based on the sizes obtained above and %%width/%%height values, determine the wleft and wtop positions of window centered within the unobscured area;
  • use wleft and wtop thus obtained instead of CW_USEDEFAULT values in the CreateMainWindow macro found in WinUtil.inc.

chrisc

  • Guest
Re: How to size the window in OpenGL
« Reply #3 on: April 15, 2018, 07:30:22 PM »
Thanxx Mike but this did not resolve the problem as the probleim lies in the
macro CreateMainWindow  inside winutil.inc 

it has the following fixed codes for the X and Y coordinates such that its windows will always be located
at the top left corner of the screen  where X = 0 and Y = 0

Code: [Select]
macro CreateMainWindow
  ======================
  hwnd = CreateWindowEx(
    0,                  'extended styles           
    "wins",             'class name                   
    "Main Window",      'window name 
    style,              '               
    CW_USEDEFAULT,      'default horizontal position 
    CW_USEDEFAULT,      'default vertical position   
    width,              'defined width               
    height,             'defined height               
    null,               'no parent or owner window   
    null,               'class menu used             
    inst,               'instance handle             
    null);              'no window creation data
  if not hWnd then
    MessageBox 0,"Unable to create window","problem",MB_ICONERROR
    exit function
  end if
  end macro


i tried to change this macro to below, but fail as it gives a run time error
Code: [Select]
' custom made for Rotate Quad2
  macro CreateMainWindowSpQ
  ======================
  hwnd = CreateWindowEx(
    0,                  'extended styles           
    "wins",             'class name                   
    "Main Window",      'window name 
    style,              '               
    100,      'default horizontal position 
    100,      'default vertical position   
    width,              'defined width               
    height,             'defined height               
    null,               'no parent or owner window   
    null,               'class menu used             
    inst,               'instance handle             
    null);              'no window creation data
  if not hWnd then
    MessageBox 0,"Unable to create window","problem",MB_ICONERROR
    exit function
  end if
  end macro
  '

i think only Charles can fix this problem as we cannot just lock the window to the top left corner
i have atteched the modified codes comprising of winutilSpQ.inc and OpenglSceneFrameSpq.inc that did not work




Mike Lobanovsky

  • Guest
Re: How to size the window in OpenGL
« Reply #4 on: April 15, 2018, 10:53:43 PM »
Yes Chris,

OpenGL uses glWinUtil.inc rather than WinUtil.inc but both includes seem to fail to handle window sizes and positions correctly. Either file inclusion doesn't work or the macro engine is failing somewhere.

Let's wait till Charles has his say.

Arnold

  • Guest
Re: How to size the window in OpenGL
« Reply #5 on: April 15, 2018, 11:05:06 PM »
Hi Chris,

I think it is not a good idea to modify the provided include files. Sometimes I use some routines of an include file to add or modify a feature, but I always use the original include files. OpenglSceneFrame.inc is a very progressive tool with a lot of options - see the many possible % constants for different behaviour. I am sure there are other possible options for your problem.

Roland

Mike Lobanovsky

  • Guest
Re: How to size the window in OpenGL
« Reply #6 on: April 15, 2018, 11:08:43 PM »
Hi Roland,

No, the include files are definitely failing. The CreateWindowEx() APIs don't follow literal window sizes within both include files. This isn't how it should be in a flawless framework, sorry.

Arnold

  • Guest
Re: How to size the window in OpenGL
« Reply #7 on: April 16, 2018, 01:46:23 AM »
This would be my (simple) solution. Maybe there are better solutions, but OpenglSceneFrame.inc is a little bit beyond my scope. At least I can create e.g. a 400*300 centered window.

Code: OxygenBasic
  1.   $ FileName  "QuadRotate3.exe"
  2.   'include    "RTL32.inc"
  3.  'include    "RTL64.inc"
  4. 'uses console
  5.  
  6.   % width     400
  7.   % height    300
  8.  
  9.   $ title     "Rotating Quad2"
  10.    % ExplicitMain
  11.  
  12.                        
  13.    uses    "OpenglSceneFrame"
  14.  
  15. % SM_CYCAPTION 4
  16. % SWP_NOZORDER 0X4
  17. % SWP_NOSIZE 0X1
  18.  
  19. sub Center(sys hwnd)
  20.     RECT rc
  21.     sys x,y
  22.     GetWindowRect(hwnd,&rc)
  23.     x = (GetSystemMetrics(SM_CXSCREEN) - (rc.right-rc.left))\2
  24.     y = (GetSystemMetrics(SM_CYSCREEN) - (rc.bottom-rc.top+GetSystemMetrics(SM_CYCAPTION)))\2
  25.  
  26.     SetWindowPos (hWnd, 0, x, y, 0, 0, SWP_NOSIZE)
  27. end sub
  28.  
  29.   function WndMessages( hWnd, wMsg, wParam, lparam ) as sys, link WndProcExtra
  30.   ============================================================================
  31.   select wMsg
  32.   ===========
  33.      
  34.   case WM_ACTIVATE
  35.       Center(hWnd)
  36.   end select
  37.  
  38.   end function
  39.  
  40. '  Note that we must specify exactly these equates
  41. '  all in uppercase ,  otherwise it can results in compilation errors
  42. #define GL_TRIANGLES        0x0004
  43. #define GL_TRIANGLE_FAN 0x0006
  44. #define GL_QUAD_STRIP     0x0008
  45.  
  46.  
  47.  
  48.   sub initialize(sys hWnd)
  49.   '=======================
  50.  end sub
  51.   '
  52.  
  53.  
  54.  
  55.  
  56.   sub scene(sys hWnd)
  57.   '==================
  58.  '
  59.  static single s1,s2,s3,s4,ang1
  60.   ActiveFrame
  61.  
  62. '  increase this angle for faster rotation between 1 and 10
  63.   angi1=1
  64.   '
  65.  glLoadIdentity
  66.   glClear GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT
  67.  
  68.  '  Greenish Beige background color
  69.   glClearColor .91,.94,.82,1
  70.   '
  71.  '
  72.  s1=.2    'x y
  73.  s2=-1    'z
  74.  s3=0.5   'color
  75.  s4=s3*.2 'color
  76.  '
  77.  glrotatef ang1, 0,0,1
  78.  
  79.  
  80.  
  81.     'draws a 3D cube object  -- drawcube  works
  82.       glTranslatef 1.4,0.0,-5.0
  83.       glBegin  GL_QUADS
  84.         glRotatef  ang1, 1.0, 1.0, 1.0         ' Rotate the quad on the X axis
  85.       glcolor3ub 255,0,0
  86.        glVertex3f  0.5,  0.5, -0.5    ' Top right of the quad (Top)
  87.       glVertex3f -0.5,  0.5, -0.5    ' Top left of the quad (Top)
  88.       glVertex3f -0.5,  0.5,  0.5    ' Bottom left of the quad (Top)
  89.       glVertex3f  0.5,  0.5,  0.5    ' Bottom right of the quad (Top)
  90.  
  91.        glcolor3ub 255,255,0
  92.        glVertex3f  0.5, -0.5,  0.5    ' Top right of the quad (Bottom)
  93.       glVertex3f -0.5, -0.5,  0.5    ' Top left of the quad (Bottom)
  94.       glVertex3f -0.5, -0.5, -0.5    ' Bottom left of the quad (Bottom)
  95.       glVertex3f  0.5, -0.5, -0.5    ' Bottom right of the quad (Bottom)
  96.  
  97.        glcolor3ub 255,0,255
  98.        glVertex3f  0.5,  0.5,  0.5    ' Top right of the quad (Front)
  99.       glVertex3f -0.5,  0.5,  0.5    ' Top left of the quad (Front)
  100.       glVertex3f -0.5, -0.5,  0.5    ' Bottom left of the quad (Front)
  101.       glVertex3f  0.5, -0.5,  0.5    ' Bottom right of the quad (Front)
  102.  
  103.        glcolor3ub 0,0,255
  104.        glVertex3f  0.5, -0.5, -0.5    ' Top right of the quad (Back)
  105.       glVertex3f -0.5, -0.5, -0.5    ' Top left of the quad (Back)
  106.       glVertex3f -0.5,  0.5, -0.5    ' Bottom left of the quad (Back)
  107.       glVertex3f  0.5,  0.5, -0.5    ' Bottom right of the quad (Back)
  108.  
  109.        glcolor3ub 0,255,255
  110.        glVertex3f -0.5,  0.5,  0.5    ' Top right of the quad (Left)
  111.       glVertex3f -0.5,  0.5, -0.5    ' Top left of the quad (Left)
  112.       glVertex3f -0.5, -0.5, -0.5    ' Bottom left of the quad (Left)
  113.       glVertex3f -0.5, -0.5,  0.5    ' Bottom right of the quad (Left)
  114.  
  115.        glcolor3ub 255,128,0
  116.        glVertex3f  0.5,  0.5, -0.5    ' Top right of the quad (Right)
  117.       glVertex3f  0.5,  0.5,  0.5    ' Top left of the quad (Right)
  118.       glVertex3f  0.5, -0.5,  0.5    ' Bottom left of the quad (Right)
  119.       glVertex3f  0.5, -0.5, -0.5    ' Bottom right of the quad (Right)
  120.    glEnd
  121.    
  122.   sleep (2)
  123.  
  124.    glLoadIdentity
  125.       glTranslatef 1.5, 0.0, -7.0            ' Move right 1.5 units and into the screen
  126.      glRotatef  ang1, 1.0, 1.0, 1.0         ' Rotate the quad on the X axis
  127.      glBegin  GL_QUADS
  128.          glColor3f   0.0,  1.0,  0.0         ' Set the color to green
  129.         glVertex3f  1.0,  1.0, -1.0         ' Top right of the quad (Top)
  130.         glVertex3f -1.0,  1.0, -1.0         ' Top left of the quad (Top)
  131.         glVertex3f -1.0,  1.0,  1.0         ' Bottom left of the quad (Top)
  132.         glVertex3f  1.0,  1.0,  1.0         ' Bottom right of the quad (Top)
  133.  
  134.          glColor3f   1.0,  0.5,  0.0         ' Set the color to orange
  135.         glVertex3f  1.0, -1.0,  1.0         ' Top right of the quad (Bottom)
  136.         glVertex3f -1.0, -1.0,  1.0         ' Top left of the quad (Bottom)
  137.         glVertex3f -1.0, -1.0, -1.0         ' Bottom left of the quad (Bottom)
  138.         glVertex3f  1.0, -1.0, -1.0         ' Bottom right of the quad (Bottom)
  139.  
  140.          glColor3f   1.0,  0.0,  0.0         ' Set the color to red
  141.         glVertex3f  1.0,  1.0,  1.0         ' Top right of the quad (Front)
  142.         glVertex3f -1.0,  1.0,  1.0         ' Top left of the quad (Front)
  143.         glVertex3f -1.0, -1.0,  1.0         ' Bottom left of the quad (Front)
  144.         glVertex3f  1.0, -1.0,  1.0         ' Bottom right of the quad (Front)
  145.  
  146.          glColor3f   1.0,  1.0,  0.0         ' Set the color to yellow
  147.         glVertex3f  1.0, -1.0, -1.0         ' Top right of the quad (Back)
  148.         glVertex3f -1.0, -1.0, -1.0         ' Top left of the quad (Back)
  149.         glVertex3f -1.0,  1.0, -1.0         ' Bottom left of the quad (Back)
  150.         glVertex3f  1.0,  1.0, -1.0         ' Bottom right of the quad (Back)
  151.  
  152.          glColor3f   0.0,  0.0,  1.0         ' Set the color to blue
  153.         glVertex3f -1.0,  1.0,  1.0         ' Top right of the quad (Left)
  154.         glVertex3f -1.0,  1.0, -1.0         ' Top left of the quad (Left)
  155.         glVertex3f -1.0, -1.0, -1.0         ' Bottom left of the quad (Left)
  156.         glVertex3f -1.0, -1.0,  1.0         ' Bottom right of the quad (Left)
  157.  
  158.          glColor3f   1.0,  0.0,  1.0         ' Set the color to violet
  159.         glVertex3f  1.0,  1.0, -1.0         ' Top right of the quad (Right)
  160.         glVertex3f  1.0,  1.0,  1.0         ' Top left of the quad (Right)
  161.         glVertex3f  1.0, -1.0,  1.0         ' Bottom left of the quad (Right)
  162.         glVertex3f  1.0, -1.0, -1.0         ' Bottom right of the quad (Right)
  163.      glEnd
  164.  
  165.  
  166.    sleep (2)
  167.  '   draw the pyramid using triangles
  168. ' // Reset the view
  169.      glLoadIdentity
  170.  
  171.       glTranslatef -1.5, 0.0, -6.0           ' Move left 1.5 units and into the screen
  172.      glRotatef  ang1, 0.0, 1.0, 0.0          ' Rotate the triangle on the Y axis
  173.  
  174.       glBegin %GL_TRIANGLES
  175.          ' Front
  176.         glColor3f   1.0,  0.0,  0.0         ' Red
  177.         glVertex3f  0.0,  1.0,  0.0         ' Top of triangle (Front)
  178.         glColor3f   0.0,  1.0,  0.0         ' Green
  179.         glVertex3f -1.0, -1.0,  1.0         ' Left of triangle (Front)
  180.         glColor3f   0.0,  0.0,  1.0         ' Blue
  181.         glVertex3f  1.0, -1.0,  1.0         ' Right of triangle (Front)
  182.  
  183.          ' Right
  184.         glColor3f   1.0,  0.0,  0.0         ' Red
  185.         glVertex3f  0.0,  1.0,  0.0         ' Top of triangle (Right)
  186.         glColor3f   0.0,  0.0,  1.0         ' Blue
  187.         glVertex3f  1.0, -1.0,  1.0         ' Left of triangle (Right)
  188.         glColor3f   0.0,  1.0,  0.0         ' Green
  189.         glVertex3f  1.0, -1.0, -1.0         ' Right of triangle (Right)
  190.  
  191.          ' Back
  192.         glColor3f   1.0,  0.0,  0.0         ' Red
  193.         glVertex3f  0.0,  1.0,  0.0         ' Top of triangle (Back)
  194.         glColor3f   0.0,  1.0,  0.0         ' Green
  195.         glVertex3f  1.0, -1.0, -1.0         ' Left of triangle (Back)
  196.         glColor3f   0.0,  0.0,  1.0         ' Blue
  197.         glVertex3f -1.0, -1.0, -1.0         ' Right of triangle (Back)
  198.  
  199.          ' Left
  200.         glColor3f   1.0,  0.0,  0.0         ' Red
  201.         glVertex3f  0.0,  1.0,  0.0         ' Top of triangle (Left)
  202.         glColor3f   0.0,  0.0,  1.0         ' Blue
  203.         glVertex3f -1.0, -1.0, -1.0         ' Left of triangle (Left)
  204.         glColor3f   0.0,  1.0,  0.0         ' Green
  205.         glVertex3f -1.0, -1.0,  1.0         ' Right of triangle (Left)
  206.      glEnd
  207.  
  208.   '
  209.  'UPDATE ROTATION ANGLES
  210.  '----------------------
  211.  '
  212.  ang1+=angi1
  213.   if ang1>360 then ang1-=360
  214.   '
  215.  end sub
  216.  
  217.  
  218.   sub Release(sys hwnd)
  219.   '====================
  220.  end sub
  221.  
  222.  
  223. MainWindow     width,height, %WS_POPUP 'WS_OVERLAPPEDWINDOW
  224.  

Charles Pegge

  • Guest
Re: How to size the window in OpenGL
« Reply #8 on: April 16, 2018, 02:01:43 AM »
Thank you gentlemen,

I think this will be satisfactory: an optional parameter when calling MainWindow
0 a default position
1 top left
2 central
3 top right

One complication is that width and height refer to the exact dimensions of the client area, rather than the whole window. I would like to keep this feature for the purpose of shooting precise screenshots (Ctrl-P) of the graphics area. So the central and right placements are slightly adjusted to allow for a regular thick-framed window.


Code: [Select]
  MainWindow width,height,WS_OVERLAPPEDWINDOW,2 'CENTRAL

from WinUtil.inc
Code: [Select]
  Function MainWindow(int width,height,style,place=0)
  =================================================
  '
  select place 'default, left, centre, right
  case 0 : hpos=32 : vpos=32
  case 1 : hpos=0: vpos=0
  case 2 : hpos=(wawidth-width)>>1 : vpos=(WaHeight-height-32)>>1
  case 3 : hpos=wawidth-width-6 : vpos=0
  end select
  '
...

Just drop the inc files into the inc folder.

Arnold

  • Guest
Re: How to size the window in OpenGL
« Reply #9 on: April 16, 2018, 02:24:59 AM »
Hi Charles,

applying your solution is of course the best way. So the lines 15-38 of my code are not necessary.

Roland

Mike Lobanovsky

  • Guest
Re: How to size the window in OpenGL
« Reply #10 on: April 16, 2018, 02:55:01 AM »
Thanks Charles,

As for me, that's going to be an acceptable palliation since center window is what I'd mostly use in my everyday work.

Mike Lobanovsky

  • Guest
Re: How to size the window in OpenGL
« Reply #11 on: April 16, 2018, 03:14:39 AM »
Roland,

Your GetSystemMetrics(SM_CXSCREEN/SM_CYSCREEN) doesn't take into account the screen area obscured by the system tray -- the strip (usually at the bottom of the screen) where the main menu orb and program icons reside. Depending on the tray settings, its on-screen size and position may vary greatly. I've seen some weird desktop layouts where the tray would stay glued to the side of the screen with multiple icon instances unstacked, so that its width would amount to probably 20% of the entire screen. Therefore your window simply won't appear centered exactly within such a desktop's visible area.

Prefer to use SystemParametersInfo() w/ SPI_GETWORKAREA for this purpose. It will guarantee the window to be centered exactly with respect to the actual position and height/breadth of the system tray.

Charles Pegge

  • Guest
Re: How to size the window in OpenGL
« Reply #12 on: April 16, 2018, 03:38:14 AM »
I like the central position too. We could set the defaults for MainWindow in WinUtil:

Code: [Select]
  Function MainWindow
  ===================
  (
    int width=640,
    height=640,
    style=WS_OVERLAPPEDWINDOW,
    place=2
  )
...

Arnold

  • Guest
Re: How to size the window in OpenGL
« Reply #13 on: April 16, 2018, 04:24:43 AM »
Thank you Mike for the info. SystemParametersInfo seems to be more versatile and also more complex than GetSystemMetrics. There are 31 topics in the Win32 Help File concerning this function. I will have to find some examples to understand SystemParametersInfo better.

Roland

Charles Pegge

  • Guest
Re: How to size the window in OpenGL
« Reply #14 on: April 16, 2018, 05:42:06 AM »
It is very loosely typed. The equate values are listed, and well documented:

https://msdn.microsoft.com/en-us/library/windows/desktop/ms724947(v=vs.85).aspx

Code: [Select]
  /*
  https://msdn.microsoft.com/en-us/library/windows/desktop/ms724947(v=vs.85).aspx

  BOOL WINAPI SystemParametersInfo(
  _In_    UINT  uiAction,
  _In_    UINT  uiParam,
  _Inout_ PVOID pvParam,
  _In_    UINT  fWinIni
  );

  'uiAction
  % SPI_GETWORKAREA     0x0030
  'fWinIni
  % SPIF_UPDATEINIFILE  0x01
  % SPIF_SENDCHANGE     0x02

 
  */

  int hpos,vpos,WaWidth,WaHeight
  int spinfo[4]
  scope
    SystemParametersInfo 0x0030,0,@spinfo,0
    indexbase 1
    WaWidth=spinfo[3]
    WaHeight=spinfo[4]
  end scope