Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
This just demostrates that OGL is possible, but is very hard. another thing is that consumes 100% of cpu time because is inside a loop, i think it should be placed in the wm_paint message if we could access it in the dialog.
;Open GL Rotating Cube ;Translated to WB ;Guido 03/03 Opengl32=dllload(strcat(dirwindows(1),"Opengl32.dll")) user32=dllload(strcat(dirwindows(1),"user32.dll")) gdi32=dllload(strcat(dirwindows(1),"gdi32.dll")) RECT=binaryalloc(16) GL_MODELVIEW=5888 GL_COLOR_BUFFER_BIT=16384 GL_DEPTH_BUFFER_BIT=256 GL_LIGHTING=2896 GL_LIGHT0=16384 GL_QUADS=7 GL_PROJECTION=5889 GL_FLAT=7424 GL_SMOOTH=7425 GL_DEPTH_TEST=2929 GL_CULL_FACE=2884 PFD_SUPPORT_OPENGL=32 PFD_DOUBLEBUFFER=1 PFD_DRAW_TO_WINDOW=4 PFD_TYPE_RGBA=0 PFD_MAIN_PLANE=0 ;translates from double to single #definefunction MakeFloat(double) oleaut32=strcat(dirwindows(1),"oleaut32.dll") db=BinaryAlloc(8) BinaryPokeFlt(db,0,double) d1=BinaryPeek4(db,0) d2=BinaryPeek4(db,4) fb=BinaryAlloc(4) DllCall(oleaut32, long:"VarR4FromR8",long:d1,long:d2,lpbinary:fb) BinaryEODSet(fb,4) r=BinaryPeek4(fb,0) BinaryFree(db) BinaryFree(fb) return r #endfunction #definefunction HandleError(Result,Text) If Result==0 Message("Error",Text) exit endif #endfunction ;make some float constants for later use f_2_0=MakeFloat(-2.0) f_1_0=MakeFloat(-1.0) f0_5=MakeFloat(0.5) f1=MakeFloat(1) f1_0=MakeFloat(1.0) f5_0=MakeFloat(5.0) f_0_5=MakeFloat(-0.5) ZoomFactor=f1 RollAxisX=0 RollAxisY=0 RollAxisZ=0 RotateSpeedX=5.0 ;f5_0 ; The speed of the rotation For the 3 axis RotateSpeedY=0 RotateSpeedZ=5.0 ;f5_0 ;exit #definesubroutine DrawCube(hdc) dllcall(Opengl32,long:"glPushMatrix") ;Save the original Matrix coordinates dllcall(Opengl32,long:"glMatrixMode",long:GL_MODELVIEW) dllcall(Opengl32,long:"glTranslatef",long:0,long:0,long:ZoomFactor) ;move it forward a bit ;dllcall(Opengl32,long:"glRotatef",long:RollAxisX,long:f1_0,long:0,long:0) ;rotate around X axis ;dllcall(Opengl32,long:"glRotatef",long:RollAxisY,long:0,long:f1_0,long:0) ;rotate around Y axis ;dllcall(Opengl32,long:"glRotatef",long:RollAxisZ,long:0,long:0,long:f1_0) ;rotate around Z axis dllcall(Opengl32,long:"glRotatef",long:makefloat(RollAxisX),long:f1_0,long:0,long:0) ;rotate around X axis dllcall(Opengl32,long:"glRotatef",long:makefloat(RollAxisY),long:0,long:f1_0,long:0) ;rotate around Y axis dllcall(Opengl32,long:"glRotatef",long:makefloat(RollAxisZ),long:0,long:0,long:f1_0) ;rotate around Z axis RollAxisX = RollAxisX + RotateSpeedX RollAxisY = RollAxisY + RotateSpeedY RollAxisZ = RollAxisZ + RotateSpeedZ ;clear framebuffer And depth-buffer dllcall(Opengl32,long:"glClear",long:GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT) ;draw the faces of a cube ;draw colored faces dllcall(Opengl32,long:"glDisable",long:GL_LIGHTING) dllcall(Opengl32,long:"glBegin",long:GL_QUADS) ; Build a face, composed of 4 vertex ! ; glBegin() specify how the vertexes are considered. Here a group of ; 4 vertexes (GL_QUADS) form a rectangular surface. ; Now, the color stuff: It's r,v,b but with float values which ; can go from 0.0 To 1.0 (0 is .. zero And 1.0 is full intensity) dllcall(Opengl32,long:"glNormal3f",long:0,long:0,long:f1_0) dllcall(Opengl32,long:"glColor3f",long:0,long:0,long:f1_0) dllcall(Opengl32,long:"glVertex3f",long:f0_5,long:f0_5,long:f0_5) dllcall(Opengl32,long:"glColor3f",long:0,long:f1_0,long:f1_0) dllcall(Opengl32,long:"glVertex3f",long:f_0_5,long:f0_5,long:f0_5) dllcall(Opengl32,long:"glColor3f",long:f1_0,long:f1_0,long:f1_0) dllcall(Opengl32,long:"glVertex3f",long:f_0_5,long:f_0_5,long:f0_5) dllcall(Opengl32,long:"glColor3f",long:0,long:0,long:0) dllcall(Opengl32,long:"glVertex3f",long:f0_5,long:f_0_5,long:f0_5) ; The other face is the same than the previous one ; except the colour which is nice blue To white gradiant dllcall(Opengl32,long:"glNormal3f",long:0,long:0,long:f_1_0) dllcall(Opengl32,long:"glColor3f",long:0,long:0,long:f1_0) dllcall(Opengl32,long:"glVertex3f",long:f_0_5,long:f_0_5,long:f_0_5) dllcall(Opengl32,long:"glColor3f",long:0,long:0,long:f1_0) dllcall(Opengl32,long:"glVertex3f",long:f_0_5,long:f_0_5,long:f_0_5) dllcall(Opengl32,long:"glColor3f",long:f1_0,long:f1_0,long:f1_0) dllcall(Opengl32,long:"glVertex3f",long:f0_5,long:f0_5,long:f_0_5) dllcall(Opengl32,long:"glColor3f",long:f1_0,long:f1_0,long:f1_0) dllcall(Opengl32,long:"glVertex3f",long:f0_5,long:f_0_5,long:f_0_5) dllcall(Opengl32,long:"glEnd") ; draw shaded faces dllcall(Opengl32,long:"glEnable",long:GL_LIGHTING) dllcall(Opengl32,long:"glEnable",long:GL_LIGHT0) dllcall(Opengl32,long:"glBegin",long:GL_QUADS) dllcall(Opengl32,long:"glNormal3f",long:0,long:f1_0,long:0) dllcall(Opengl32,long:"glVertex3f",long:f0_5,long:f0_5,long:f0_5) dllcall(Opengl32,long:"glVertex3f",long:f0_5,long:f0_5,long:f_0_5) dllcall(Opengl32,long:"glVertex3f",long:f_0_5,long:f0_5,long:f_0_5) dllcall(Opengl32,long:"glVertex3f",long:f_0_5,long:f0_5,long:f0_5) dllcall(Opengl32,long:"glNormal3f",long:0,long:f_1_0,long:0) dllcall(Opengl32,long:"glVertex3f",long:f_0_5,long:f_0_5,long:f_0_5) dllcall(Opengl32,long:"glVertex3f",long:f0_5,long:f_0_5,long:f_0_5) dllcall(Opengl32,long:"glVertex3f",long:f0_5,long:f_0_5,long:f0_5) dllcall(Opengl32,long:"glVertex3f",long:f_0_5,long:f_0_5,long:f0_5) dllcall(Opengl32,long:"glNormal3f",long:f1_0,long:0,long:0) dllcall(Opengl32,long:"glVertex3f",long:f0_5,long:f0_5,long:f0_5) dllcall(Opengl32,long:"glVertex3f",long:f0_5,long:f_0_5,long:f0_5) dllcall(Opengl32,long:"glVertex3f",long:f0_5,long:f_0_5,long:f_0_5) dllcall(Opengl32,long:"glVertex3f",long:f0_5,long:f0_5,long:f_0_5) dllcall(Opengl32,long:"glNormal3f",long:f_1_0,long:0,long:0) dllcall(Opengl32,long:"glVertex3f",long:f_0_5,long:f_0_5,long:f_0_5) dllcall(Opengl32,long:"glVertex3f",long:f_0_5,long:f_0_5,long:f0_5) dllcall(Opengl32,long:"glVertex3f",long:f_0_5,long:f0_5,long:f0_5) dllcall(Opengl32,long:"glVertex3f",long:f_0_5,long:f0_5,long:f_0_5) dllcall(Opengl32,long:"glEnd") dllcall(Opengl32,long:"glPopMatrix") dllcall(Opengl32,long:"glFinish") dllcall(gdi32,long:"SwapBuffers",long:hdc) #endsubroutine BoxesUp("200,200,800,800", @normal) hwnd=dllhwnd("") hdc=dllcall(user32,long:"GetDC",long:hwnd) dllcall(user32,long:"GetClientRect",long:hwnd,lpbinary:RECT) WindowWidth=binarypeek4(RECT,8) WindowHeight=binarypeek4(RECT,12) PIXELFORMATDESCRIPTOR=binaryalloc(40) binarypoke2(PIXELFORMATDESCRIPTOR,0,40) ;nSize binarypoke2(PIXELFORMATDESCRIPTOR,2,1) ;nVersion binarypoke4(PIXELFORMATDESCRIPTOR,4,PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER|PFD_DRAW_TO_WINDOW) ;dwFlags binarypoke(PIXELFORMATDESCRIPTOR,8,PFD_TYPE_RGBA) ;iPixelType binarypoke(PIXELFORMATDESCRIPTOR,9,16) ;cColorBits binarypoke(PIXELFORMATDESCRIPTOR,24,16) ;cDepthBits binarypoke4(PIXELFORMATDESCRIPTOR,29,PFD_MAIN_PLANE) ;dwLayerMask pixformat=dllcall(gdi32,long:"ChoosePixelFormat",long:hdc,lpbinary:PIXELFORMATDESCRIPTOR) HandleError(pixformat,"ChoosePixelFormat") r=dllcall(gdi32,long:"SetPixelFormat",long:hdc,long:pixformat,lpbinary:PIXELFORMATDESCRIPTOR) HandleError(r,"SetPixelFormat") hrc=dllcall(Opengl32,long:"wglCreateContext",long:hdc) HandleError(hrc,"wglCreateContext") r=dllcall(Opengl32,long:"wglMakeCurrent",long:hdc,long:hrc) HandleError(r,"wglMakeCurrent") dllcall(Opengl32,long:"glMatrixMode",long:GL_PROJECTION) ; position viewer dllcall(Opengl32,long:"glMatrixMode",long:GL_MODELVIEW) dllcall(Opengl32,long:"glTranslatef",long:0,long:0,long:f_2_0) FlatMode=0 If FlatMode dllcall(Opengl32,long:"glShadeModel",long:GL_FLAT) Else dllcall(Opengl32,long:"glShadeModel",long:GL_SMOOTH) EndIf dllcall(Opengl32,long:"glEnable",long:GL_DEPTH_TEST) ; Enabled, it slowdown a lot the rendering. It's to be sure than the ; rendered objects are inside the z-buffer. dllcall(Opengl32,long:"glEnable",long:GL_CULL_FACE) ; This will enhance the rendering speed as all the back face will be ; ignored. This works only with CLOSED objects like a cube... Singles ; planes surfaces will be visibles only on one side. dllcall(Opengl32,long:"glViewport",long:0,long:0,long:WindowWidth-30,long:WindowHeight-30) ; A rectangle which define the OpenGL output zone while 1 DrawCube(hdc) endwhile
Article ID: W15932
File Created: 2004:03:30:15:41:44
Last Updated: 2004:03:30:15:41:44