![]() widgetGetSize :: WidgetClass widget => widget -> IO (Int, Int) To draw the resizable figure, we need to get the size of the drawing area each time Note that setSourceRGB not only takes a Doubleīetween 0 and 1 as its parameters instead of Int values between 5,īut also 'lives' within the Render monad instead of the IO monad. The paint function paints the current source everywhere within the currentĬlip region. Set the background color with the paint function, instead of widgetModify. Now the drawing will always fit the borders defined by the parameters. To do this we need: myDraw :: Double -> Double -> Render () This example does not really do what we want because, though the figure is redrawn, Window do renderWithDrawable drawin myDraw Window can be used to draw on! import Graphics.UI.Gtk WidgetGetDrawWindow function in the code below. This fits what is required, so we use: onExpose canvas (\x -> do renderWithDrawable drawin myDrawĪ frame has also been included, for visual effect, but this is inessential.īut note that the widgetShowAll function appears before the There is another event, however, the Expose event, which sends a signalĮach time the window is resized or redrawn on the screen. ![]() This actually works.Įach time the window is resized the drawing disappears, and it is drawn again when you click One possibility would beĪn onButtonPress event as used in Chapter 6.2 with the Event Box. Now you can use: renderWithDrawable :: DrawableClass drawable => drawable -> Render a -> IO aīut this drawing must be executed in response to an event. To get it you use: widgetGetDrawWindow :: WidgetClass widget => widget -> IO DrawWindowĭrawingAreaGetDrawWindow :: DrawingArea -> IO DrawWindow However, you don't draw on this widget itself, the canvas in the example below,īut on its DrawWindow. For this we need a blank widget, with DrawingArea type. First, however, the color of the lines and their width must The actual drawing of this path is done by the They do not, however,ĭraw anything, but rather define a path, which is to be followed. ![]() LineTo and closePath functions, which do what the names suggest. The figure, a triangle, is defined by the moveTo, Note that this is not the IO monad, which is The type of this function is Render () and from the do notation you can gather Then the following function defines an actual drawing: myDraw :: Render () The goal of this appendix is to explain what basic functions you need.įirst the Cairo Graphics module must be imported with import. Postscript (ps) or scaleable vector graphics (svg) formats of any Cairo drawing uses some special syntax in Gtk2Hs. See the Cairo Documentation Site for that.ĭrawing to the screen or in portable network graphics (png), portable document format (pdf), Though that subject is large enough to merit its own tutorials. Drawing in Gtk2Hs is not very different from drawing in original Cairo, It is possible to draw quite complex figures in Gtk2Hs, on screen and in several file formats, The original source did not credit it.Gtk2Hs Tutorial Previous Home Drawing with Cairo: Getting Started You know, I feel really bad about putting this image here, since I can't seem to find where it came from. Have a basic understanding of this new type of program flow Have a working shape on your screen Replace call to Enable/Disable Texture and DrawSquare() with our own code Draw a single triangle in immediate modeĢ0 Added code T1.ActivateTexture( 0 ) DrawSquare() Ĭhange Render State T1.ActivateTexture( 0 ) DrawSquare() glBegin( GL_TRIANGLES ) glColor3f ( 1.0, 0.0, 0.0 ) glVertex3f( 0.0, 1.0, 0.0 ) glColor3f ( 0.0, 1.0, 0.0 ) glVertex3f( 1.0, 0.0, 0.0 ) glColor3f ( 0.0, 0.0, 1.0 ) glVertex3f( 0.0, 0.0, 0.0 ) glEnd() T1.DeactivateTexture( 0 ) Vertex Attribute (R,G,B) Vertex Location (X,Y,Z)Ģ1 Review Understand the difference from this and traditional programming #include int AddTwoNumbers( int a, int b ) Swap front buffer with back buffer (cue to self: talk about double-buffering) Tell system to redraw at its own leisureġ9 Let's add some code Modify the MyDraw() function. To ask questions and interrupt me a lot.Ĥ Tool Set C Most game programming is still done in C īasic code is very similar to other high level languages OpenGL Works everywhere (Except XBOX 360) Exposes more of the background GLUT cppgpgpu Get moving - fast.ĥ C/C Background You #include definitions You write functions Understand what makes it different from normal programming. What's different Getting started Get a working demo Add some code Reviewģ Why? Get a grasp on the way of thinking. Not jumping in.Ģ Overview Why you're here What you'll be using Background of C Lesson 1 Understanding the basics of C Game Programming using OpenGL (and GLUT) This is geared toward getting your feet wet.
0 Comments
Leave a Reply. |