Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.15 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.  
  11. #define G_SCR_W (480)
  12. #define G_SCR_H (272)
  13. #define G_FALSE 0
  14. #define G_TRUE !0
  15.  
  16. #define G_RGBA(r,g,b,a) \
  17.   ((r)|((g)<<8)|((b)<<16)|((a)<<24))
  18.  
  19. #define G_GET_R(color) (((color)    ) & 0xFF)
  20. #define G_GET_G(color) (((color)>>8 ) & 0xFF)
  21. #define G_GET_B(color) (((color)>>16) & 0xFF)
  22. #define G_GET_A(color) (((color)>>24) & 0xFF)
  23.  
  24. #define G_MODULATE(color,luminance,alpha) \
  25.   G_RGBA(luminance*G_GET_R(color)/255, \
  26.          luminance*G_GET_G(color)/255, \
  27.          luminance*G_GET_B(color)/255, \
  28.          alpha    *G_GET_A(color)/255)
  29.  
  30. enum gColors
  31. {
  32.   // Primary colors
  33.   RED          = 0xFF0000FF,
  34.   GREEN        = 0xFF00FF00,
  35.   BLUE         = 0xFFFF0000,
  36.   // Secondary colors
  37.   CYAN         = 0xFFFFFF00,
  38.   MAGENTA      = 0xFFFF00FF,
  39.   YELLOW       = 0xFF00FFFF,
  40.   // Tertiary colors
  41.   AZURE        = 0xFFFF7F00,
  42.   VIOLET       = 0xFFFF007F,
  43.   ROSE         = 0xFF7F00FF,
  44.   ORANGE       = 0xFF007FFF,
  45.   CHARTREUSE   = 0xFF00FF7F,
  46.   SPRING_GREEN = 0xFF7FFF00,
  47.   // Grayscale
  48.   WHITE        = 0xFFFFFFFF,
  49.   LITEGRAY     = 0xFFBFBFBF,
  50.   GRAY         = 0xFF7F7F7F,
  51.   DARKGRAY     = 0xFF3F3F3F,  
  52.   BLACK        = 0xFF000000
  53. };
  54.  
  55. // First gEnum is the default.
  56. enum Coord_Modes { G_UP_LEFT, G_UP_RIGHT, G_DOWN_RIGHT, G_DOWN_LEFT, G_CENTER };
  57. enum Rotation_Modes { G_EACH_OBJ, G_POINT };
  58.  
  59. typedef char bool;
  60. typedef unsigned char gAlpha;
  61. typedef unsigned int gColor;
  62. typedef int gEnum;
  63.  
  64. typedef struct
  65. {
  66.   int texW, texH;
  67.   int imgW, imgH;
  68.   float ratio;
  69.   bool swizzled;
  70.   gColor* data;
  71. } gImage;
  72.  
  73. void gClear(gColor color, bool zclear); // Clears screen & depth buffer
  74. void gBegin(); // Begin Object
  75. void gEnd(); // End & draw Object
  76. void gReset(); // Call all gReset* functions (for gSetRelative* stuff)
  77. void gFlip(bool vsync); // Flip the screen
  78.  
  79. // All gSet* functions must be called between gBegin() & gEnd()
  80. // All gSetRelative* functions are relative to the others gSet* functions parameters
  81.  
  82. void gResetCoord(); // Set to G_UP_LEFT and (0.f;0.f;0.f)
  83. void gSetCoordMode(gEnum mode); // TODO Choose between Coord_Modes
  84. void gSetCoordXY(float x, float y); // New object (or vertex)
  85. void gSetCoordXYZ(float x, float y, float z); // New object (or vertex) with zbuffer
  86. void gSetCoordXYRelative(float x, float y);
  87. void gSetCoordXYZRelative(float x, float y, float z);
  88.  
  89. // TODO
  90. void gResetCrop();
  91. void gSetCropXY(int x, int y); // Image part to blit, position
  92. void gSetCropWH(int w, int h); // Image part to blit, size
  93. void gSetCropXYRelative(int x, int y);
  94. void gSetCropWHRelative(int w, int h);
  95.  
  96. void gResetScale(); // Set scale to 1.f,1.f
  97. void gSetScale(float w, float h); // Set scale from 0.f to 1.f, value can be negative to invert
  98. void gSetScaleWH(int w, int h); // Set new width & height, an alternative to gSetScale
  99. void gSetScaleRelative(float w, float h);
  100. void gSetScaleWHRelative(int w, int h);
  101.  
  102. void gResetColor(); // Set color to WHITE
  103. void gResetAlpha(); // Set alpha to 255
  104. void gSetColor(gColor color); // Set color of the object, used to colorize it
  105. void gSetAlpha(gAlpha alpha); // Set alpha of the object, proportionnal with the color alpha.
  106. void gSetAlphaRelative(gAlpha alpha);
  107.  
  108. // TODO
  109. void gResetRotation(); // Set rotation to 0° & G_EACH_OBJ
  110. void gSetRotationMode(gEnum mode); // Choose between Rotation_Modes
  111. void gSetRotationXY(float x, float y); // Set the center of the rotation, absolute with G_POINT, or relative with XY with G_EACH_OBJ
  112. void gSetRotationAngle(float degrees); // Sets the rotation angle, in degrees.
  113. void gSetRotationAngleRad(float radians); // Sets the rotation angle, in radians.
  114. void gSetRotationXYRelative(float x, float y);
  115. void gSetRotationAngleRelative(float degrees);
  116. void gSetRotationAngleRadRelative(float radians);
  117.  
  118. // TODO
  119. gImage* gTexLoad(const char path[], bool swizzle); // Load an image file, can be swizzled (fastest)
  120. void gSetTex(gImage* img, bool blend); // Apply a texture to an object, blend can be enabled
  121.  
  122. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement