Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.94 KB | None | 0 0
  1. // gLib2D by Geecko - A simple, fast, light-weight 2D graphics library.
  2. //
  3. // This work is licensed under the Creative Commons BY-SA 3.0 Unported License.
  4. // See LICENSE for more details.
  5.  
  6. #ifndef GLIB2D_H
  7. #define GLIB2D_H
  8.  
  9. //#define USE_VFPU TODO
  10. #define USE_PNG
  11. //#define USE_JPG TODO
  12.  
  13. #define G_SCR_W (480)
  14. #define G_SCR_H (272)
  15. #define G_FALSE 0
  16. #define G_TRUE !0
  17.  
  18. #define G_RGBA(r,g,b,a) \
  19.   ((r)|((g)<<8)|((b)<<16)|((a)<<24))
  20.  
  21. #define G_GET_R(color) (((color)    ) & 0xFF)
  22. #define G_GET_G(color) (((color)>>8 ) & 0xFF)
  23. #define G_GET_B(color) (((color)>>16) & 0xFF)
  24. #define G_GET_A(color) (((color)>>24) & 0xFF)
  25.  
  26. #define G_MODULATE(color,luminance,alpha) \
  27.   G_RGBA(luminance*G_GET_R(color)/255, \
  28.          luminance*G_GET_G(color)/255, \
  29.          luminance*G_GET_B(color)/255, \
  30.          alpha    *G_GET_A(color)/255)
  31.  
  32. enum gColors
  33. {
  34.   // Primary colors
  35.   RED          = 0xFF0000FF,
  36.   GREEN        = 0xFF00FF00,
  37.   BLUE         = 0xFFFF0000,
  38.   // Secondary colors
  39.   CYAN         = 0xFFFFFF00,
  40.   MAGENTA      = 0xFFFF00FF,
  41.   YELLOW       = 0xFF00FFFF,
  42.   // Tertiary colors
  43.   AZURE        = 0xFFFF7F00,
  44.   VIOLET       = 0xFFFF007F,
  45.   ROSE         = 0xFF7F00FF,
  46.   ORANGE       = 0xFF007FFF,
  47.   CHARTREUSE   = 0xFF00FF7F,
  48.   SPRING_GREEN = 0xFF7FFF00,
  49.   // Grayscale
  50.   WHITE        = 0xFFFFFFFF,
  51.   LITEGRAY     = 0xFFBFBFBF,
  52.   GRAY         = 0xFF7F7F7F,
  53.   DARKGRAY     = 0xFF3F3F3F,  
  54.   BLACK        = 0xFF000000
  55. };
  56.  
  57. // First gEnum is the default.
  58. enum Coord_Modes { G_UP_LEFT, G_UP_RIGHT, G_DOWN_RIGHT, G_DOWN_LEFT, G_CENTER };
  59.  
  60. typedef char bool;
  61. typedef unsigned char gAlpha;
  62. typedef unsigned int gColor;
  63. typedef int gEnum;
  64.  
  65. typedef struct
  66. {
  67.   int tw, th;
  68.   int w, h;
  69.   float ratio;
  70.   bool swizzled;
  71.   gColor* data;
  72. } gImage;
  73.  
  74. void gClear(gColor color); // Clears screen & depth buffer (if used in the loop)
  75. void gClearZ(); // Clears depth buffer
  76. void gBegin(gImage* tex, bool use_tex_blend); // Begin Object
  77. void gEnd(); // End & draw Object
  78. void gReset(); // Call all gReset* functions (for gSetRelative* stuff)
  79. void gFlip(bool vsync); // Flip the screen
  80. void gAdd(); // Adds an obj to the render list.
  81.  
  82. // Transform stack
  83. void gPush();
  84. void gPop();
  85.  
  86. // All gSet* functions must be called between gBegin() & gEnd()
  87. // All gSetRelative* functions are relative to the others gSet* functions parameters
  88.  
  89. void gResetCoord(); // Set to G_UP_LEFT and (0.f;0.f;0.f)
  90. void gSetCoordMode(gEnum mode); // Choose between Coord_Modes
  91. void gSetCoordXY(float x, float y); // New object (or vertex)
  92. void gSetCoordXYZ(float x, float y, float z); // New object (or vertex) with zbuffer
  93. void gSetCoordXYRelative(float x, float y, bool use_rot);
  94. void gSetCoordXYZRelative(float x, float y, float z, bool use_rot);
  95.  
  96. void gResetCrop();
  97. void gSetCropXY(int x, int y); // Image part to blit, position
  98. void gSetCropWH(int w, int h); // Image part to blit, size
  99. void gSetCropXYRelative(int x, int y);
  100. void gSetCropWHRelative(int w, int h);
  101.  
  102. void gResetScale(); // Set scale to 1.f,1.f
  103. void gSetScale(float w, float h); // Set scale from 0.f to 1.f, value can be negative to invert
  104. void gSetScaleWH(int w, int h); // Set new width & height, an alternative to gSetScale
  105. void gSetScaleRelative(float w, float h);
  106. void gSetScaleWHRelative(int w, int h);
  107.  
  108. void gResetColor(); // Set color to WHITE
  109. void gResetAlpha(); // Set alpha to 255
  110. void gSetColor(gColor color); // Set color of the object, used to colorize it
  111. void gSetAlpha(gAlpha alpha); // Set alpha of the object, proportionnal with the color alpha.
  112. void gSetAlphaRelative(gAlpha alpha);
  113.  
  114. void gResetRotation(); // Set rotation to 0°
  115. void gSetRotationRad(float radians); // Sets the rotation angle, in radians.
  116. void gSetRotation(float degrees); // Sets the rotation angle, in degrees.
  117. void gSetRotationRadRelative(float radians);
  118. void gSetRotationRelative(float degrees);
  119.  
  120. gImage* gTexLoad(char path[], bool swizzle); // Load an image file, can be swizzled (fastest)
  121.  
  122. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement