Re: Win32Lib + OpenGL = Love
- Posted by cklester <cklester at yahoo.com> Jul 29, 2004
- 530 views
Chris Burch wrote: > > BTW, small challenge, what would the code be for generating one white > triangle, fullscreen, centred and slightly translated into the screen, > only using truegl as an include, and NO others. I've been struggling > with this for 24 hours, no doubt 5 mins to you ( ) Since truegl depends on Win32Lib for its GUI, you have to include win32lib. You can use mic's opengl code, or evan marshall's opengl code, if you don't want to use win32lib. Anyway, here's code for drawing a simple quad on a fullscreen in windows: --start of simple OpenGL code include Win32Lib.ew include truegl.e --create the window constant win = createEx( Window, "EUPHORIA + OpenGL Demo - Triangle", 0, Default, Default, 640, 480, {WS_POPUP, WS_DLGFRAME}, 0 ) -- draw our quadrangle procedure display() glClear(GL_COLOR_BUFFER_BIT + GL_DEPTH_BUFFER_BIT) glLoadIdentity() glTranslatef(0.0,0.0,-4.0) glBegin(GL_QUADS) 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() special_SwapBuffers() end procedure --set up our environment when we start procedure win_onOpen (integer self, integer event, sequence params) init_opengl_window(win,or_all({PFD_DOUBLEBUFFER,PFD_GENERIC_ACCELERATED}),PFD_TYPE_RGBA,1) glShadeModel(GL_SMOOTH) glClearColor(0.0, 0.0, 0.0, 0.5) glClearDepth(1.0) glEnable(GL_DEPTH_TEST) glDepthFunc(GL_LEQUAL) glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) glDisable(GL_DITHER) if setIdle(True) then end if end procedure setHandler( win, w32HOpen, routine_id("win_onOpen")) --window is open, set up remaining environment vars procedure win_onActivate(integer self, integer event, sequence params) sequence rect integer width, height rect = getClientRect(win) width = rect[3]-rect[1] height=rect[4]-rect[2] glViewport(0,0,width,height) glMatrixMode(GL_PROJECTION) -- Select The Projection Matrix glLoadIdentity() -- Reset The Projection Matrix gluPerspective(45.0,width/height,0.1,100.0) glMatrixMode(GL_MODELVIEW) -- Select The Modelview Matrix glLoadIdentity() -- Reset The Modelview Matrix display() end procedure setHandler( win, w32HActivate, routine_id("win_onActivate")) procedure do_display(integer self, integer event, sequence params) display() end procedure setHandler(win,{w32HPaint,w32HIdle},routine_id("do_display")) WinMain( win,Maximize ) -=ck "Programming in a state of EUPHORIA." http://www.cklester.com/euphoria/