[perl-win32-gui-users] win32-gui opengl

2009-07-10 Thread peter
hello
thanks kevin for the opengl example.
i have used his example to display a triangle which can be rotated in a 3D
space using the  up down left right  keys.
also added a button and a textbox, i have 2 question:
1- i can rotate the triangle by keys, until i click on the button to display
some text in the textbox, why is this behaviour, and how i can restore the
triangle rotating after clicking the button.
2- is it possible to make the opengl window smaller than the win32gui window
!!
best wishes
peter
--
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge___
Perl-Win32-GUI-Users mailing list
Perl-Win32-GUI-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users
http://perl-win32-gui.sourceforge.net/

[perl-win32-gui-users] win32 gui opengl

2009-07-10 Thread peter
hello
thanks kevin for the opengl example.
i have used his example to display a triangle which can be rotated in a 3D
space using the  up down left right  keys.
also added a button and a textbox, i have 2 question:
1- i can rotate the triangle by keys, until i click on the button to display
some text in the textbox, why is this behaviour, and how i can restore the
triangle rotating after clicking the button.
2- is it possible to make the opengl window smaller than the win32gui window
!!
best wishes
attached below the code, and for your convenience from here:
http://rapidshare.com/files/254072142/triangle.rar
peter

  use strict;
  use warnings;
  #these constants are needed for SetPixelFormat() but aren't defined in
Win32::GUI
  use constant {
  PFD_TYPE_RGBA => 0,
  PFD_DOUBLEBUFFER => 0x0001,
  PFD_DRAW_TO_WINDOW => 0x0004,
  PFD_SUPPORT_OPENGL => 0x0020,
  PFD_MAIN_PLANE => 0,
  };
  use OpenGL qw(:glfunctions :glconstants :glufunctions);
  #use OpenGL qw(:all);
  use Win32::API;
  use Win32::GUI qw();
  use Win32::GUI::Carp qw(warningsToDialog fatalsToDialog immediateWarnings
winwarn windie);
  use Win32::GUI::Constants qw(IDI_APPLICATION WS_CLIPCHILDREN
WS_CLIPSIBLINGS
  WM_CREATE WM_SIZE WM_CLOSE VK_ESCAPE CW_USEDEFAULT MB_OK
MB_ICONEXCLAMATION);
  my $g_HDC; #global handle to device context
  my $hRC; #handle to rendering context
  my $rtri  = 0.0;
  my $xrot = 0;
  my $yrot = 0;
#define PIXELFORMATDESCRIPTOR struct used for the SetPixelFormat function
#refer to the Windows SDK documentation for more info about this structure
  Win32::API::Struct->typedef(
  PIXELFORMATDESCRIPTOR => qw(
  WORD nSize;
  WORD nVersion;
  DWORD dwFlags;
  BYTE iPixelType;
  BYTE cColorBits;
  BYTE cRedBits;
  BYTE cRedShift;
  BYTE cGreenBits;
  BYTE cGreenShift;
  BYTE cBlueBits;
  BYTE cBlueShift;
  BYTE cAlphaBits;
  BYTE cAlphaShift;
  BYTE cAccumBits;
  BYTE cAccumRedBits;
  BYTE cAccumGreenBits;
  BYTE cAccumBlueBits;
  BYTE cAccumAlphaBits;
  BYTE cDepthBits;
  BYTE cStencilBits;
  BYTE cAuxBuffers;
  BYTE iLayerType;
  BYTE bReserved;
  DWORD dwLayerMask;
  DWORD dwVisibleMask;
  DWORD dwDamageMask;
  )
  );
#needed for the wglMakeCurrent functions
  Win32::API::Type->typedef('HGLRC', 'HANDLE');
#import some extra functions
#more info can be found in the Windows SDK documentation
#exchanges the front and back buffers of the current pixel format
  Win32::API->Import('gdi32', 'BOOL SwapBuffers(HDC hdc);')
  or windie "Win32::API->Import(SwapBuffers): $^E";
#attempts to match an appropriate pixel format supported by a device context
to
# a given pixel format specification.
  Win32::API->Import('gdi32', 'int ChoosePixelFormat(HDC hdc,
PIXELFORMATDESCRIPTOR * ppfd);')
  or windie "Win32::API->Import(ChoosePixelFormat): $^E";
#sets the pixel format of the specified device context to the format
specified
# by the iPixelFormat index returned from ChoosePixelFormat().
  Win32::API->Import('gdi32', 'BOOL SetPixelFormat(HDC hdc, int
iPixelFormat, PIXELFORMATDESCRIPTOR * ppfd);')
  or windie "Win32::API->Import(SetPixelFormat): $^E";
#creates a new OpenGL rendering context, which is suitable for drawing on
the
# device referenced by hdc.
  Win32::API->Import('opengl32', 'HGLRC wglCreateContext(HDC hdc);')
  or windie "Win32::API->Import(wglCreateContext): $^E";
#makes a specified OpenGL rendering context the calling thread's current
# rendering context.
  Win32::API->Import('opengl32', 'BOOL wglMakeCurrent(HDC hdc, HGLRC
hglrc);')
  or windie "Win32::API->Import(wglMakeCurrent): $^E";
#deletes a specified OpenGL rendering context.
  Win32::API->Import('opengl32', 'BOOL wglDeleteContext(HGLRC hglrc);')
  or windie "Win32::API->Import(wglDeleteContext): $^E";
#create main window
  my $main = Win32::GUI::Window->new(
  -name => "main",
  -text => "OpenGL Example: Colour Cube",
  -size => [640,480],
  -left => CW_USEDEFAULT, #let system position window
  -pushstyle =>
#Excludes the area occupied by child windows when drawing occurs
# within the parent window.
  WS_CLIPCHILDREN |
#When a particular child window needs to be painted, all other overlapping
# child windows are clipped out of the region of the child window to be
updated.
  WS_CLIPSIBLINGS,
  -onTerminate => sub { #WM_CLOSE
  wglMakeCurrent($g_HDC->Handle(), 0); #deselect rendering context from $hDC
  wglDeleteContext($hRC); #delete rendering context $hRC
  return -1; #exit main loop
  },
  -onResize => sub { #WM_SIZE
  my $self = shift;
  return 0 unless $self;
  my $height = $self->Height(); #get height and width
  my $width = $self->Width();
  $height = 1 if $height == 0; #don't divide by 0
  glViewport(0,0,$width,$height); #set viewport to new dimensions
  glMatrixMode(GL_PROJECTION); #set matrix mode to projection matrix
  glLoadIdentity(); #reset projection matrix
  gluPerspective(54.0, $width / $height, 1.0, 1000.0); #calculate aspect
ratio of window
  glMatrixMode(GL_MODELVIEW); #set modelview matrix
  glLoadIdentity(); #reset modelview matrix
  r