Eine Pyramide wird mit 2 Buttons gedreht.
Im GrafikForum habe ich noch eine Frage mit den Bildern laden in Opengl,
vielleicht kann mir einer helfen.
Code: Alles auswählen
IncludeFile "opengl.pb"
Structure GLscreen
container.l
hWnd.l
hDC.l
EndStructure
Procedure OpenGLScreen(*p.GLscreen,x,y,w,h)
If *p
container = ContainerGadget(#PB_Any,x,y,w,h)
If container
hwnd = GadgetID(container)
pfd.PIXELFORMATDESCRIPTOR
hdc = GetDC_(hwnd)
pfd\nSize = SizeOf(PIXELFORMATDESCRIPTOR)
pfd\nVersion = 1
pfd\dwFlags = #PFD_SUPPORT_OPENGL | #PFD_DOUBLEBUFFER | #PFD_DRAW_TO_WINDOW
pfd\iLayerType = #PFD_MAIN_PLANE
pfd\iPixelType = #PFD_TYPE_RGBA
pfd\cColorBits = 24
pfd\cDepthBits = 16
pixformat = ChoosePixelFormat_(hdc, pfd)
SetPixelFormat_(hdc, pixformat, pfd)
hrc = wglCreateContext_(hdc)
wglMakeCurrent_(hdc, hrc)
SwapBuffers_(hdc)
glClearColor_(0.0, 0.0, 0.0, 1.0)
*p\container = container
*p\hWnd = GadgetID(container)
*p\hDC = hdc
ProcedureReturn 1
EndIf
EndIf
EndProcedure
If OpenWindow(0, 0, 0, 800,600, "TEST",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CreateGadgetList(WindowID(0))
ButtonGadget(0,520,10,80,20, "links")
ButtonGadget(1,520,40,80,20, "rechts")
If OpenGLScreen(screen.GLscreen,10,10,500,500)
HideWindow(0,0)
Repeat
glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
glLoadIdentity_()
glRotatef_(xrot.f,1.0,1.0,1.0)
glBegin_(#GL_POLYGON)
glColor3f_(1.0, 0.0, 0.0)
glVertex3f_(0, 0.8, 0) ; top
glColor3f_(0.0, 1.0, 0.0)
glVertex3f_(-0.5, -0.5, 0.5) ; left
glColor3f_(0.0, 0.0,1.0)
glVertex3f_(0.5, -0.5, 0.5) ; right
glColor3f_(1.0,0.0,0.0) ; Red
glVertex3f_( 0.0, 0.8, 0.0) ; Top Of Triangle (Right)
glColor3f_(0.0,0.0,1.0) ; Blue
glVertex3f_( 0.5,-0.5, 0.5) ; Left Of Triangle (Right)
glColor3f_(0.0,0.5,0.0) ; Green
glVertex3f_( 0.5,-0.5, -0.5) ; Right Of Triangle (Right)
glColor3f_(1.0,0.0,0.0) ; Red
glVertex3f_( 0.0, 0.8, 0.0) ; Top Of Triangle (Back)
glColor3f_(0.0,1.0,0.0) ; Green
glVertex3f_( 0.5,-0.5, -0.5) ; Left Of Triangle (Back)
glColor3f_(0.0,0.0,1.0) ; Blue
glVertex3f_(-0.5,-0.5, -0.5) ; Right Of Triangle (Back)
glColor3f_(1.0,0.0,0.0) ; Red
glVertex3f_( 0.0, 0.8, 0.0) ; Top Of Triangle (Left)
glColor3f_(0.0,0.0,1.0) ; Blue
glVertex3f_(-0.5,-0.5,-0.5) ; Left Of Triangle (Left)
glColor3f_(0.0,1.0,0.0) ; Green
glVertex3f_(-0.5,-0.5, 0.5) ; Right Of Triangle (Left)
glEnd_()
SwapBuffers_(screen\hdc)
Event = WaitWindowEvent()
WindowID = EventWindow()
GadgetID = EventGadget()
EventType = EventType()
If Event = #PB_Event_Gadget
If GadgetID = 0
xrot.f=xrot.f+5
EndIf
If GadgetID = 1
xrot.f=xrot.f-5
EndIf
EndIf
Until Event = #PB_Event_CloseWindow
ReleaseDC_(screen\hWnd,screen\hDC)
EndIf
EndIf