Hi Charles,
here I come to my limits with using console.inc, although I think I can narrow down the problem. I completed the Nehe Tutorial No 7 and added Menu and Key actions. Probably I did it not the best way and I did not exhaust all the possibilities of OxygenSceneFrame, but it is only a draft at the moment.
The app works quite nice in 32-bit, but in 64-bit I will get an error: "SetMenu hMenu failed!". If I comment out: initMenu(hWnd) in about line 319, the keys like F1 or Ctrl-O will not work nevertheless in 64-bit. If I apply: printl "wMsg = " wMsg in about line 313, most of the time wMsg prints 0, which is not correct.
After more testing I found that the demos \examples\OpenGl\MenuObj.o2bas and \other WndMenus.o2bas do also not work in 64-bit, so I assume it is a problem with the option: , link WndProcExtra? Perhaps a cast must be used somewhere? But at the moment I have no idea what is missing and if the reason is really the link option.
Roland
' OPENGL NEHE tutorial Example Chapter 7
$ FileName "Nehe7_OSF.exe"
'uses rtl32
'uses rtl64
uses FileDialog
#case capital
def NULL null
% review
uses dialogs
% ExplicitMain
% title = "Nehe Tutorial 7 with OpenglSceneFrame"
uses OpenglSceneFrame
string fn=""
sys HelpDlg
'Ids for menu
#define IDM_Load 1110
#define IDM_Exit 1111
#define IDM_Reset 1112
#define IDM_Help 1113
#define IDM_Right 1114
#define IDM_Left 1115
#define IDM_Up 1116
#define IDM_Down 1117
#define IDM_PgUp 1118
#define IDM_PgDown 1119
'Ids for text controls in Help
% IDC_LText1=1131
% IDC_LText2=1132
float xspeed=0
float yspeed=0
float z_depth=5
bool light
GLfloat LightAmbient[]= { 0.5f, 0.5f, 0.5f, 1.0f }
GLfloat LightDiffuse[]= { 1.0f, 1.0f, 1.0f, 1.0f }
GLfloat LightPosition[]= { 0.0f, 0.0f, 2.0f, 1.0f }
int filter // Which Filter To Use
width=500 : height=300
MainWindow width,height,WS_OVERLAPPEDWINDOW
printl "Enter ..."
waitkey
end
declare sub initMenu(sys hWnd)
==========================================================================
sys GdiplusToken
sys texn[16]
'CREATE OPENGL TEXTURE
'=====================
type ColorPixel
byte red,green,blue,alpha
=
dword colorx
end type
'------------------------------------------------------
Sub MakeTexture(sys pPixelArray, TextureWidth, TextureHeight, *Texnum )
'======================================================
'
string strTextureData
glEnable GL_TEXTURE_2D
// Create Nearest Filtered Texture
glBindTexture(GL_TEXTURE_2D, TexNum[0])
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST)
glTexImage2D GL_TEXTURE_2D, 0, 4, TextureWidth, TextureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, pPixelArray
// Create Linear Filtered Texture
glBindTexture GL_TEXTURE_2D, TexNum[1]
glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR
glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR
glTexImage2D GL_TEXTURE_2D, 0, 4, TextureWidth, TextureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, pPixelArray
// Create MipMapped Texture
glBindTexture(GL_TEXTURE_2D, TexNum[2])
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST)
gluBuild2DMipmaps GL_TEXTURE_2D, 4, TextureWidth, TextureHeight, GL_RGBA, GL_UNSIGNED_BYTE, pPixelArray
'
'---------------- important for all 6 faces to show in openGL scene --------- //
glClearDepth 1.0
' Specify the value used for depth-buffer comparisons
glDepthFunc GL_LESS
' Enable depth comparisons and update the depth buffer
glEnable GL_DEPTH_TEST
' Select smooth shading
glShadeModel GL_SMOOTH
'
'---------------- important for all 6 faces to show in openGL scene --------- //
glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient) // Setup The Ambient Light
glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse) // Setup The Diffuse Light
glLightfv(GL_LIGHT1, GL_POSITION,LightPosition) // Position The Light
glEnable(GL_LIGHT1) // Enable Light One
End Sub
'============================
'GDIPLUS TEXTURE IMAGE LOADER
'============================
'-----------------------------------------------------
function loadTexture(string wszfilename, sys textureWidth, sys textureHeight, string*strTextureData) as sys
'=====================================================
'
sys hstatus,pImage,pThumb,token
sys width,height,picflip,picdim,ref,xw,yw,xww,yww
macro swap(a,b)
scope
let _v_ = a : a=b : b= _v_
end scope
end macro
'
GdiplusStartupInput StartupInput
StartupInput.GdiplusVersion = 1
hStatus=GdiplusStartup token, StartupInput, byval 0
'
if hStatus then
mbox "Error initializing GDIplus: " hex hStatus
exit function
end if
if len(fn) then
hStatus = GdipLoadImageFromFile wszfilename, pImage
if hStatus != 0 then mbox "Cannot load: " wszfilename
hStatus = GdipGetImageThumbnail pImage, textureWidth, textureHeight, pThumb, NULL, NULL
end if
picflip=pthumb
hStatus = GdipImageRotateFlip (picflip,6) ' RotateNoneFlipY =6 invert
colorpixel colpix
strTextureData=nuls 4*textureWidth*textureHeight
xww=textureWidth-1
yww=xww
picdim=*strTextureData
for yw=0 to yww ' first y: right flip direction
for xw=0 to xww
GdipBitmapGetPixel picflip, xw, yw, colpix.colorx
swap colpix.red, colpix.blue
*picdim=colpix.colorx
picdim+=4 'increase
next
next
'
'Cleanup
'
if pThumb then GdipDisposeImage pThumb
if pImage then GdipDisposeImage pImage
return hStatus
GdiplusShutdown token
end Function
'-----------------------
sub Initialize(sys hWnd)
'=======================
'GDIPLUS
'=======
string txt
sys hr
GdiplusStartupInput StartupInput
StartupInput.GdiplusVersion = 1
hr=GdiplusStartup GdiplusToken, StartupInput, byval 0
'
if hr then
mbox "Error initializing GDIplus: " hex hr
exit function
end if
'
'Prepare Textures (in IDM_Load)
'----------------
'
'
SetTimer hWnd,1,10,NULL
end sub
sub Release(sys hWnd)
'====================
killTimer hwnd, 1
glDeleteTextures 1, texn
GdiplusShutdown GdiplusToken
'
end sub
static float xrotation = 0
static float yrotation = 0
sub scene(sys hWnd)
'==================
'
static single ang1
static single sx,sy,sz
'
glClear GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT
glClearColor 0, 0, 0, 0 '0.5, 0, 0, 0
glLoadIdentity
'
'ACTIVATE TEXTURE
'----------------
'
glEnable GL_TEXTURE_2D
glBindTexture GL_TEXTURE_2D,texn[filter]
'
sx=0.2 : sy=0.16 : sz=-1
'
'MOVEMENT
'--------
'
single x=cos(rad(ang1))*.1 ,y=sin(rad(ang1))*.1,z=0
glTranslatef x+0, y+0, z-z_depth
glRotatef xrotation, 0, 1, 0
xrotation+=xspeed
if xrotation > 360 then
xrotation -= 360
end if
glRotatef yrotation, 1, 0, 0
yrotation+=yspeed
if yrotation > 360 then
yrotation -= 360
end if
'
'DRAW SHAPE
'----------
'
'this quad is drawn clockwise
'
glbegin GL_QUADS
'
' Front Face
glNormal3f 0.0 , 0.0 , 1.0
glTexCoord2f 0.0 , 0.0 : glVertex3f -1.0 , -1.0 , 1.0
glTexCoord2f 1.0 , 0.0 : glVertex3f 1.0 , -1.0 , 1.0
glTexCoord2f 1.0 , 1.0 : glVertex3f 1.0 , 1.0 , 1.0
glTexCoord2f 0.0 , 1.0 : glVertex3f -1.0 , 1.0 , 1.0
' Back Face
glNormal3f 0.0 , 0.0 , -1.0
glTexCoord2f 1.0 , 0.0 : glVertex3f -1.0 , -1.0 , -1.0
glTexCoord2f 1.0 , 1.0 : glVertex3f -1.0 , 1.0 , -1.0
glTexCoord2f 0.0 , 1.0 : glVertex3f 1.0 , 1.0 , -1.0
glTexCoord2f 0.0 , 0.0 : glVertex3f 1.0 , -1.0 , -1.0
' Top Face
''glNormal3f 0.0 , 1.0 , 0.0
glTexCoord2f 0.0 , 1.0 : glVertex3f -1.0 , 1.0 , -1.0
glTexCoord2f 0.0 , 0.0 : glVertex3f -1.0 , 1.0 , 1.0
glTexCoord2f 1.0 , 0.0 : glVertex3f 1.0 , 1.0 , 1.0
glTexCoord2f 1.0 , 1.0 : glVertex3f 1.0 , 1.0 , -1.0
' Bottom Face
''glNormal3f 0.0 ,-1.0 , 0.0
glTexCoord2f 1.0 , 1.0 : glVertex3f -1.0 , -1.0 , -1.0
glTexCoord2f 0.0 , 1.0 : glVertex3f 1.0 , -1.0 , -1.0
glTexCoord2f 0.0 , 0.0 : glVertex3f 1.0 , -1.0 , 1.0
glTexCoord2f 1.0 , 0.0 : glVertex3f -1.0 , -1.0 , 1.0
' Right face
''glNormal3f 1.0 , 0.0 , 0.0
glTexCoord2f 1.0 , 0.0 : glVertex3f 1.0 , -1.0 , -1.0
glTexCoord2f 1.0 , 1.0 : glVertex3f 1.0 , 1.0 , -1.0
glTexCoord2f 0.0 , 1.0 : glVertex3f 1.0 , 1.0 , 1.0
glTexCoord2f 0.0 , 0.0 : glVertex3f 1.0 , -1.0 , 1.0
' Left Face
''glNormal3f -1.0 , 0.0 , 0.0
glTexCoord2f 0.0 , 0.0 : glVertex3f -1.0 , -1.0 , -1.0
glTexCoord2f 1.0 , 0.0 : glVertex3f -1.0 , -1.0 , 1.0
glTexCoord2f 1.0 , 1.0 : glVertex3f -1.0 , 1.0 , 1.0
glTexCoord2f 0.0 , 1.0 : glVertex3f -1.0 , 1.0 , -1.0
glEnd
glend
'
glDisable GL_TEXTURE_2D
'
'
end sub
function WndMessages( sys hWnd, uint wMsg, sys wParam, lParam ) as sys, link WndProcExtra
============================================================================
string sep=chr(0)
string ImgFilter=
"images"+sep+"*.bmp;*.jpg;*.jpeg;*.png;*.ico;*.tif;*tiff;*.gif"+sep+
"all files"+sep+"*.*"+sep+sep
'printl "wMsg = " wMsg
select wMsg
===========
case WM_CREATE
if mincreate then return
initMenu(hWnd)
case WM_COMMAND
select case loword(wParam) 'id
case IDM_Exit
SendMessage hwnd, WM_CLOSE, 0, 0
return 1 'indicate this message has been intercepted / no further action
'
case IDM_Load
'Prepare Textures
'----------------
glGenTextures 2, texn
static sys res=512
string imgs[1]=""
fn=GetFileName("", 0, ImgFilter)
LoadTexture fn, res,res, imgs[1]
MakeTexture *imgs[1],res,res,texn
case IDM_Reset
xspeed=0
yspeed=0
z_depth=5
xrotation=0
yrotation=0
case IDM_Help
'Create Help Window if not already exist
if IsWindow(HelpDlg) = 0 then
Dialog( 0, 0, 200, 150, "Buttons used:",
WS_OVERLAPPED or WS_SYSMENU or DS_CENTER or WS_VISIBLE or DS_SETFONT,
8, "MS Sans Serif" )
Ltext( "", IDC_LText1, 5, 5, 50, 120 )
Ltext( "", IDC_LText2, 55, 5,110, 120 )
HelpDlg = CreateModelessDialog( hwnd, @HelpDlgProc, 0 )
else
ShowWindow(HelpDlg, SW_SHOW)
end if
end select
case WM_KEYDOWN
printl wParam
select case loword(wParam)
case VK_F1
SendMessage(hWnd, WM_COMMAND, IDM_Help,0)
case VK_RIGHT
xspeed+=0.2
case VK_LEFT
xspeed-=0.2
case VK_UP
yspeed+=0.2
case VK_DOWN
yspeed-=0.2
case VK_NEXT 'PgDown
z_depth+=0.2
case VK_PRIOR 'PgUP
z_depth-=0.2
case vk_L
if light then light=false else light=true
if not light then glDisable(GL_LIGHTING) else glEnable(GL_LIGHTING)
case vk_F
filter+=1
if (filter>2) then filter=0
end select
case WM_CHAR
printl wParam
select case loword(wParam)
case 15 'Ctrl-O
SendMessage(hWnd, WM_COMMAND, IDM_Load,0)
case 18 'Ctrl-R
SendMessage(hWnd, WM_COMMAND, IDM_Reset,0)
end select
end select
end function
sub initMenu(sys hwnd)
sys hMenu
MENU(hMenu)
BEGIN
POPUP "&File"
BEGIN
MENUITEM "&Load Image..." tab "Ctrl+O", IDM_Load
MENUITEM "SEPARATOR"
MENUITEM "E&xit" tab "Alt+F4", IDM_Exit
ENDMenu
POPUP "&View"
BEGIN
MENUITEM "&Reset" tab "Ctrl+R", IDM_Reset
ENDMenu
POPUP "&Help"
BEGIN
MENUITEM "&Key Options" tab "F1", IDM_Help
ENDMenu
ENDMenu
if SetMenu( hWnd, hMenu ) = 0 then
mbox "SetMenu hMenu failed!"
end if
end sub
'====================================================================
function HelpDlgProc( sys hDlg, uint uMsg, sys wParam, lParam) as sys callback
string Result
sys hLText1=GetDlgItem(hDlg, IDC_LText1)
sys hLText2=GetDlgItem(hDlg, IDC_LText2)
select case uMsg
case WM_INITDIALOG
string HelpText1 =
"
F1
Ctrl-O
Ctrl-R
Left, Right
Up, Down
Page Up
Page Down
F
L
Alt-F4
ESC
"
string HelpText2 =
"
This Help
Load an image
Reset to original state
+/- rotate speed horizontal
+/- rotate speed vertical
Zoom Out
Zoom In
Change Filter (0-2)
Lighting on / off
quit
quit
"
SetWindowText (hLText1, HelpText1)
SetWindowText (hLText2, HelpText2)
case WM_CLOSE
'Hide Help Window
ShowWindow(hDlg, SW_HIDE)
end select
return 0
end function
'====================================================================