// //------------------ DOK FILE -------------------------------------------------- +Header core.2d.gl =pkg core.2d.gl =title core.2d.gl =short a little 2d openGL library =desc This little library lets you manage a 2d screen with openGL. You don't need to care about the projections, the matrix, the frustrum or the shaders. It is based on Sprites of any size. It works closely with the core.3d.gl library. Before calling 2d functions, you should: - call once [[glInitShaders]] - create textures with [[textureCreate]] - create sprites with [[gl2dSpriteCreate]] - define colors with [[colorMakeARGB]] Then, for each frame: - call [[gl2dInitScreen]] to initialize the render buffer - call [[gl2dDrawSprite]], [[gl2dDrawColoredSprite]], [[gl2dDrawFlatBox]] to draw your things - call [[glSwapBuffers]] to send the render buffer to the screen // // //------------------ PROTO ----------------------------------------------------- gl2dDrawSprite +Proto gl2dDrawSprite =type fun Sprite Int Int -> Int =mode function =pkg core.2d.gl =impl mcy =link =desc This function draws a sprite at a given position. // +arg s =type Sprite =desc A sprite // +arg x =type Int =desc An integer // +arg y =type Int =desc An integer // +arg result =type Int =desc Always 0 // // //------------------ PROTO ----------------------------------------------------- gl2dDrawColoredSprite +Proto gl2dDrawColoredSprite =type fun Sprite Int Int Floats -> Int =mode function =pkg core.2d.gl =impl mcy =link =desc This function draws a filtered sprite at a given position. The filter is a color multiplication. // +arg s =type Sprite =desc A sprite // +arg x =type Int =desc An integer // +arg y =type Int =desc An integer // +arg color =type Floats =desc A color vector. See [[colorMakeARGB]] // +arg result =type Int =desc Always 0 // // //------------------ PROTO ----------------------------------------------------- gl2dSpriteUpdateTexture +Proto gl2dSpriteUpdateTexture =type fun Sprite -> Int =mode function =pkg core.2d.gl =impl mcy =link =desc The sprite's texture is updated. This means that the openGL texture is updated with the content of its attached bitmap. See [[textureUpdate]]. // +arg s =type Sprite =desc A sprite // +arg result =type Int =desc Always 0 // // //------------------ PROTO ----------------------------------------------------- gl2dSpriteUpdateUV +Proto gl2dSpriteUpdateUV =type fun Sprite Int Int Int Int -> Sprite =mode function =pkg core.2d.gl =impl mcy =link =desc This function updates the texture coordinates of the sprite. Texture coordinates derive from a rectangle in the original bitmap coordinates. // +arg src =type Sprite =desc A sprite // +arg x =type Int =desc Any integer // +arg y =type Int =desc Any integer // +arg w =type Int =desc Any integer // +arg h =type Int =desc Any integer // +arg result =type Sprite =desc The sprite src // // //------------------ PROTO ----------------------------------------------------- gl2dSpriteCreate +Proto gl2dSpriteCreate =type fun Texture -> Sprite =mode function =pkg core.2d.gl =impl mcy =link =desc This function creates a [[Sprite]] from an openGL texture. It expects to be followed by a call to [[gl2dSpriteUpdateUV]] to definie the texture coordinates before being rendered with [[gl2dDrawSprite]]. // +arg texture =type Texture =desc A texture. See [[textureCreate]]. // +arg result =type Sprite =desc A new sprite // // //------------------ PROTO ----------------------------------------------------- gl2dDrawFlatBox +Proto gl2dDrawFlatBox =type fun Int Int Int Int Floats -> Int =mode function =pkg core.2d.gl =impl mcy =link =desc This function draws a rectangle with a flat color. // +arg x =type Int =desc Any integer // +arg y =type Int =desc Any integer // +arg w =type Int =desc Any positive integer // +arg h =type Int =desc Any positive integer // +arg color =type Floats =desc A color vector. See [[colorMakeARGB]] // +arg result =type Int =desc Always 0 // // //------------------ PROTO ----------------------------------------------------- gl2dInitScreen +Proto gl2dInitScreen =type fun Floats -> Int =mode function =pkg core.2d.gl =impl mcy =link =desc This function should be called at the begining of a rendering. It initializes the frame and applies a background color. This allows to use screen coordinates, from 0 to width or from 0 to height (instead of something like [-1, 1]), to draw things during the rendering. // +arg bgColor =type Floats =desc A color vector. See [[colorMakeARGB]] // +arg result =type Int =desc Always 0 // // //------------------ PROTO ----------------------------------------------------- gl2dDrawBackground +Proto gl2dDrawBackground =type fun Floats -> Int =mode function =pkg core.2d.gl =impl mcy =link =desc This function applies a background color. // +arg bgColor =type Floats =desc A color vector. See [[colorMakeARGB]] // +arg result =type Int =desc Always 0 // // //------------------ PROTO ----------------------------------------------------- Sprite +Proto Sprite =type Sprite =mode structure =pkg core.2d.gl =impl mcy =link =desc This is the type for sprites. A sprite is defined by: - a rectangle (width, height) - a [[Texture]], which derives from an original [[Bitmap]] - texture coordinates