Problème pour OpenGL, besoin d'aide ?
Publié : ven. 10/sept./2021 18:52
J'ai voulais coder de façon minimun pour OpenGL avec Purebasic 5.73, voici le code :
Il fonctionne mais le carré rouge se déplace puis disparait rapidement... je vois pas comment corriger ça, pourriez vous m'aider svp ? Est il bien codé ?
Code : Tout sélectionner
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
CompilerIf Subsystem("OpenGL") = #False
MessageRequester("Error", "Please set the subsystem to OpenGL")
End
CompilerEndIf
CompilerEndIf
InitEngine3D()
InitKeyboard()
OpenWindow(0, 0, 0, 800, 600, "Hello world for test with OpenGL", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, 800, 600)
Repeat
glClearColor_(0.7, 0.7, 0.7, 0) ; background color
glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
Repeat
event = WindowEvent()
Select Event
Case #PB_Event_CloseWindow
quit = 1
EndSelect
Until event = 0
glBegin_(#GL_POLYGON)
glColor3f_(1.0, 0.0, 0.0)
glVertex3f_(0.0, 0.0, 0.0)
glVertex3f_(0.5, 0.0, 0.0)
glVertex3f_(0.5, 0.5, 0.0)
glVertex3f_(0.0, 0.5, 0.0)
glEnd_()
glMatrixMode_(#GL_PROJECTION)
glLoadIdentity_();
gluPerspective_(45.0, 800/600, 1.0, 60.0)
glMatrixMode_(#GL_MODELVIEW)
glTranslatef_(0, 0, -4)
glShadeModel_(#GL_SMOOTH)
glEnable_(#GL_DEPTH_TEST)
glEnable_(#GL_CULL_FACE)
glViewport_(0, 0, 800, 600)
FlipBuffers()
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape) Or quit = 1