Тема: blitz3D + OpenGL
Показать сообщение отдельно
Старый 04.04.2010, 20:30   #1
Sayman
Оператор ЭВМ
 
Регистрация: 26.11.2007
Сообщений: 39
Написано 9 полезных сообщений
(для 12 пользователей)
blitz3D + OpenGL

Всем доброго времени. Сижу вот ковыряюсь в сабже, да наткнулся на проблему. суть в том, что я не могу сообразить, как правильно переключать приложение, написанное с преминением OpenGL, в полноэкранный режим. пробовал покапать в сторону glut - облом - при вызове функции glutInit вылетает ошибка MAV. попробовал поработать с ChangeDisplaySettings, но тут ещё сильнее закопался. по сути то перед вызовом этой функции, нужно было бы вызвать EnumDisplayDevices с целью определения девайса и прочих парамтеров. но функция эта среди параметров содержит адрес на массив... т.е. то что на бллице видимо сложновато сделать... может есть какой то способ, кто может подсказать? пример приложения привожу..он старый, но нанём пока отрабатываю.
Include "ogld_utils.bb"
Include "wgl_const.bb"
Include "gl_const.bb"
Include "glu_const.bb"
Include "blitz_gl.bb"
Include "CG.bb"
Const title$="OpenGL Direct - selection mode and name stack"
Const GLUT_RGB=0
Const GLUT_DOUBLE=2
Const GLUT_DEPTH=16
Global hRC   ; The OpenGL RenderContext
Global hMainDC  ; render window's  Device context
Global  bbHwnd  ; Windows handle.
Global GlWinW=1280 
Global GlWinH=720
Global xrot#
Global yrot#
Global xspeed# ;=.1
Global yspeed# ;=.2
; CG Vars to hold info
Global CGcontext,profile,vprogram
Global light,modelviewproj,modelviewit
Global teapotList
AppTitle title$
Global argc
Global argv
 
Graphics GlWinW,GlWinH,32,2
ChangeDisplaySettings(0,4)
AppTitle title$ 
frame=CreateTimer(60)
bbHwnd=ogld_GetWindow() ; 
If bbHwnd Then 
 pf.ogld_PixelFormat=ogld_MakeDefaultPixelFormat()
 hMainDC = ogld_SetUp_OpenGL(bbHwnd,pf)
 If Not hMainDC Then RuntimeError "Could not initialize OpenGl"
  ResizeViewport GlWinW, GlWinH
  initGL
 Else
  RuntimeError "Could not get a handle to the Blitz window"
EndIf
;glScissor 100,100,300,300
;glEnable GL_SCISSOR_TEST
While Not KeyHit(1)
WaitTimer(frame) 
 DrawGLscene
 SwapBuffers(hMainDC )
 glerr= glGetError()
 If glerr<>0 Then DebugLog "OpenGL Error:  " + glerr
    xrot = xrot + xspeed
    yrot = yrot + yspeed  
Wend 
FreeTimer(frame)  
wglMakeCurrent 0,0
If hMainDC Then
 wglDeleteContext hMainDC
End If  
If hMainDC Then
 ReleaseDC bbHwnd, hMainDC
End If       
End
Function DrawGLscene()
 glClear(GL_COLOR_BUFFER_BIT Or GL_DEPTH_BUFFER_BIT);   ; Clears the screen.
 glLoadIdentity();                   ;Reset modelview matrix for new frame.
 glMatrixMode(GL_MODELVIEW);
 glTranslatef(0,0,-10)
 glRotatef(xrot, 1.0, 0.0, 0.0);
 glRotatef( yrot, 0.0, 1.0, 0.0);
 ; Here we are binding the vertex shader To the hardware After you set the
 ; constants.
 
 ; Just like If you would like To have texture, you would need To enable texturing Right?
 ; Well To use the vertex program you must enable it like so...
 cgGLBindProgram(vprogram);
 cgGLEnableProfile(profile);
 cgGLSetParameter4f(light, 0.0, 0.0, 1.0, 1.0);
    cgGLSetStateMatrixParameter(modelviewproj, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);
    cgGLSetStateMatrixParameter(modelviewit, CG_GL_MODELVIEW_MATRIX, CG_GL_MATRIX_INVERSE_TRANSPOSE);
 glPushMatrix();
    
 glBegin(GL_QUADS);
  ;Front Face
  glNormal3f( 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);
  ;Back Face
  glNormal3f( 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);
  ;Top Face
  glNormal3f( 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);
  ;Bottom Face;
  glNormal3f( 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);
  ;Right face
  glNormal3f( 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);
  ;Left Face
  glNormal3f(-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);
 glEnd();
 glPopMatrix() 
 cgGLDisableProfile(vProfile);
    ;When we are done we disable the vertex program.
xrot=xrot+.5
yrot=yrot+.5
End Function
Function CGERROR()
cgerror=cgGetError( )
If cgerror>0
DebugLog cgGetErrorString(cgerror )
EndIf
End Function

Function ResizeViewport(nWidth,nHeight)
 Local aspect#
 If nHeight = 0 Then nHeight = 1
 glViewport 0,0,nWidth,nHeight
 glMatrixMode GL_PROJECTION
 glLoadIdentity
 aspect#=Float(nWidth)/Float(nHeight)
 gluPerspective 55.0,aspect,1.0,100.0
 glMatrixMode GL_MODELVIEW    
End Function
Function initGL()
 glClearColor (0.0, 0.0, 0.0, 0.5);        ; Black Background
 glClearDepth (1.0);            ; Depth Buffer Setup
 glDepthFunc (GL_LEQUAL);           ; The Type Of Depth Testing
 glEnable (GL_DEPTH_TEST);           ; Enable Depth Testing
 glShadeModel (GL_SMOOTH);           ; Select Smooth Shading
 glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);     ; Set Perspective Calculations To Most Accurate
 
 ; Now we take that source code And create the vertex shader out of it.
 ;cgIsProgram(program)
 If (cgGLIsProfileSupported(CG_PROFILE_ARBVP1))
  profile = CG_PROFILE_ARBVP1;
 Else If (cgGLIsProfileSupported(CG_PROFILE_VS_2_0))
       profile = CG_PROFILE_VP20;
  Else
        RuntimeError("Vertex programming extensions (GL_ARB_vertex_program or GL_NV_vertex_program) Not supported, exiting...")
 EndIf 
 CGcontext = cgCreateContext();
 
 vprogram = cgCreateProgramFromFile(CGcontext,CG_SOURCE, "simple.cg",profile, 0,0);
 cgGLLoadProgram(vprogram);
    
    Light = cgGetNamedParameter(vProgram, "LightVec");
    ModelViewProj = cgGetNamedParameter(vProgram, "ModelViewProj");
    modelviewit = cgGetNamedParameter(vprogram, "ModelViewIT");
 
End Function
 
Type ogld_PixelFormat
 Field index%
 Field Size%
 Field Version%
 Field Flags%
 Field PixelType%
 Field ColorBits%
 Field RedBits%
 Field RedShift%
 Field GreenBits%
 Field GreenShift%
 Field BlueBits%
 Field BlueShift%
 Field AlphaBits%
 Field AlphaShift%
 Field AccumBits%
 Field AccumRedBits%
 Field AccumGreenBits%
 Field AccumBlueBits%
 Field AccumAlphaBits%
 Field DepthBits%
 Field StencilBits%
 Field AuxBuffers%
 Field LayerType%
 Field Reserved%
 Field wLayerMask%
 Field wVisibleMask%
 Field wDamageMask%
End Type
 
Function ogld_MakeDefaultPixelFormat.ogld_PixelFormat()
 pf.ogld_PixelFormat=New ogld_PixelFormat
 pf\Size=40
 pf\Version=2
 pf\Flags=PFD_SUPPORT_OPENGL Or PFD_DRAW_TO_WINDOW Or PFD_DOUBLEBUFFER
 pf\PixelType=PFD_TYPE_RGBA 
 pf\ColorBits=32
 ;pf\RedBits=
 ;pf\RedShift=
 ;pf\GreenBits=
 ;pf\GreenShift=
 ;pf\BlueBits=
 ;pf\BlueShift=
 pf\AlphaBits=16
 ;pf\AlphaShift=
 ;pf\AccumBits=
 ;pf\AccumRedBits=
 ;pf\AccumGreenBits=
 ;pf\AccumBlueBits=
 pf\AccumAlphaBits=16
 pf\DepthBits=16
 pf\StencilBits=8
 ;pf\AuxBuffers=
 ;pf\LayerType=
 ;pf\Reserved=
 pf\wLayerMask=PFD_MAIN_PLANE 
 ;pf\wVisibleMask=
 ;pf\wDamageMask=
 Return pf
End Function
 
Function ogld_SetUp_OpenGL(hWnd,pf.ogld_PixelFormat)
 hDC=GetDC(hWnd)
 
 If hDC Then
  lpPixelFormat=ogld_SetupPixelFormat(hDC,pf)
 
     hRC = wglCreateContext(hDC)
     If Not hRC Then
       RuntimeError  "wglCreateContext() failed"
     End If
     wglMakeCurrent hDC, hRC  
 
 
  Return hDC
 
 Else
  RuntimeError "Can't get DC"
 EndIf
End Function
(Offline)
 
Ответить с цитированием