1 /* 2 * This file is a part of the Cairo-Dock project 3 * 4 * Copyright : (C) see the 'copyright' file. 5 * E-mail : see the 'copyright' file. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 3 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 21 #ifndef __CAIRO_DOCK_DRAW_OPENGL__ 22 #define __CAIRO_DOCK_DRAW_OPENGL__ 23 24 #include <glib.h> 25 26 #include <GL/glu.h> 27 28 #include "cairo-dock-struct.h" 29 #include "cairo-dock-opengl.h" 30 #include "cairo-dock-container.h" 31 32 G_BEGIN_DECLS 33 34 /** 35 *@file cairo-dock-draw-opengl.h This class provides some useful functions to draw with OpenGL. 36 */ 37 38 void cairo_dock_set_icon_scale (Icon *pIcon, GldiContainer *pContainer, double fZoomFactor); 39 40 void cairo_dock_set_container_orientation_opengl (GldiContainer *pContainer); 41 42 void cairo_dock_draw_icon_reflect_opengl (Icon *pIcon, CairoDock *pDock); 43 44 void cairo_dock_draw_icon_opengl (Icon *pIcon, CairoDock *pDock); 45 46 void cairo_dock_translate_on_icon_opengl (Icon *icon, GldiContainer *pContainer, double fDockMagnitude); 47 48 /** Draw an icon, according to its current parameters : position, transparency, reflect, rotation, stretching. Also draws its indicators, label, and quick-info. It generates a CAIRO_DOCK_RENDER_ICON notification. 49 *@param icon the icon to draw. 50 *@param pDock the dock containing the icon. 51 *@param fDockMagnitude current magnitude of the dock. 52 *@param bUseText TRUE to draw the labels. 53 */ 54 void cairo_dock_render_one_icon_opengl (Icon *icon, CairoDock *pDock, double fDockMagnitude, gboolean bUseText); 55 56 void cairo_dock_render_hidden_dock_opengl (CairoDock *pDock); 57 58 ////////////////// 59 // LOAD TEXTURE // 60 ////////////////// 61 /** Load a cairo surface into an OpenGL texture. The surface can be destroyed after that if you don't need it. The texture will have the same size as the surface. 62 *@param pImageSurface the surface, created with one of the 'cairo_dock_create_surface_xxx' functions. 63 *@return the newly allocated texture, to be destroyed with _cairo_dock_delete_texture. 64 */ 65 GLuint cairo_dock_create_texture_from_surface (cairo_surface_t *pImageSurface); 66 67 /** Load a pixels buffer representing an image into an OpenGL texture. 68 *@param pTextureRaw a buffer of pixels. 69 *@param iWidth width of the image. 70 *@param iHeight height of the image. 71 *@return the newly allocated texture, to be destroyed with _cairo_dock_delete_texture. 72 */ 73 GLuint cairo_dock_create_texture_from_raw_data (const guchar *pTextureRaw, int iWidth, int iHeight); 74 75 /** Load an image on the dock into an OpenGL texture. The texture will have the same size as the image. The size is given as an output, if you need it for some reason. 76 *@param cImagePath path to an image. 77 *@param fImageWidth pointer that will be filled with the width of the image. 78 *@param fImageHeight pointer that will be filled with the height of the image. 79 *@return the newly allocated texture, to be destroyed with _cairo_dock_delete_texture. 80 */ 81 GLuint cairo_dock_create_texture_from_image_full (const gchar *cImagePath, double *fImageWidth, double *fImageHeight); 82 83 /** Load an image on the dock into an OpenGL texture. The texture will have the same size as the image. 84 *@param cImagePath path to an image. 85 *@return the newly allocated texture, to be destroyed with _cairo_dock_delete_texture. 86 */ 87 #define cairo_dock_create_texture_from_image(cImagePath) cairo_dock_create_texture_from_image_full (cImagePath, NULL, NULL) 88 89 /** Delete an OpenGL texture from the Graphic Card. 90 *@param iTexture variable containing the ID of a texture. 91 */ 92 #define _cairo_dock_delete_texture(iTexture) glDeleteTextures (1, &iTexture) 93 94 /** Update the icon's texture with its current cairo surface. This allows you to draw an icon with libcairo, and just copy the result to the OpenGL texture to be able to draw the icon in OpenGL too. 95 *@param pIcon the icon. 96 */ 97 void cairo_dock_update_icon_texture (Icon *pIcon); 98 99 void cairo_dock_draw_hidden_appli_icon (Icon *pIcon, GldiContainer *pContainer, gboolean bStateChanged); 100 101 ////////////////// 102 // DRAW TEXTURE // 103 ////////////////// 104 /** Enable texture drawing. 105 */ 106 #define _cairo_dock_enable_texture(...) do { \ 107 glEnable (GL_BLEND);\ 108 glEnable (GL_TEXTURE_2D);\ 109 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);\ 110 glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);\ 111 glEnable (GL_LINE_SMOOTH);\ 112 glPolygonMode (GL_FRONT, GL_FILL); } while (0) 113 114 /** Disable texture drawing. 115 */ 116 #define _cairo_dock_disable_texture(...) do { \ 117 glDisable (GL_TEXTURE_2D);\ 118 glDisable (GL_LINE_SMOOTH);\ 119 glDisable (GL_BLEND); } while (0) 120 121 /** Set the alpha channel to a current value, other channels are set to 1. 122 *@param fAlpha alpha 123 */ 124 #define _cairo_dock_set_alpha(fAlpha) glColor4f (1., 1., 1., fAlpha) 125 126 /** Set the color blending to overwrite. 127 */ 128 #define _cairo_dock_set_blend_source(...) glBlendFunc (GL_ONE, GL_ZERO) 129 130 /** Set the color blending to mix, for premultiplied texture. 131 */ 132 #define _cairo_dock_set_blend_alpha(...) glBlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA) 133 134 /** Set the color blending to mix. 135 */ 136 #define _cairo_dock_set_blend_over(...) glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) 137 138 /** Set the color blending to mix on a pbuffer. 139 */ 140 #define _cairo_dock_set_blend_pbuffer(...) glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA) 141 142 #define _cairo_dock_apply_current_texture_at_size(w, h) do { \ 143 glBegin(GL_QUADS);\ 144 glTexCoord2f(0., 0.); glVertex3f(-.5*w, .5*h, 0.);\ 145 glTexCoord2f(1., 0.); glVertex3f( .5*w, .5*h, 0.);\ 146 glTexCoord2f(1., 1.); glVertex3f( .5*w, -.5*h, 0.);\ 147 glTexCoord2f(0., 1.); glVertex3f(-.5*w, -.5*h, 0.);\ 148 glEnd(); } while (0) 149 #define _cairo_dock_apply_current_texture_at_size_crop(iTexture, w, h, ratio) do { \ 150 glBegin(GL_QUADS);\ 151 glTexCoord2f(0., 1-ratio); glVertex3f(-.5*w, (ratio -.5)*h, 0.);\ 152 glTexCoord2f(1., 1-ratio); glVertex3f( .5*w, (ratio -.5)*h, 0.);\ 153 glTexCoord2f(1., 1); glVertex3f( .5*w, -.5*h, 0.);\ 154 glTexCoord2f(0., 1); glVertex3f(-.5*w, -.5*h, 0.);\ 155 glEnd(); } while (0) 156 #define _cairo_dock_apply_current_texture_at_size_with_offset(w, h, x, y) do { \ 157 glBegin(GL_QUADS);\ 158 glTexCoord2f(0., 0.); glVertex3f(x-.5*w, y+.5*h, 0.);\ 159 glTexCoord2f(1., 0.); glVertex3f(x+.5*w, y+.5*h, 0.);\ 160 glTexCoord2f(1., 1.); glVertex3f(x+.5*w, y-.5*h, 0.);\ 161 glTexCoord2f(0., 1.); glVertex3f(x-.5*w, y-.5*h, 0.);\ 162 glEnd(); } while (0) 163 #define _cairo_dock_apply_current_texture_portion_at_size_with_offset(u, v, du, dv, w, h, x, y) do { \ 164 glBegin(GL_QUADS);\ 165 glTexCoord2f(u, v); glVertex3f(x-.5*w, y+.5*h, 0.);\ 166 glTexCoord2f(u+du, v); glVertex3f(x+.5*w, y+.5*h, 0.);\ 167 glTexCoord2f(u+du, v+dv); glVertex3f(x+.5*w, y-.5*h, 0.);\ 168 glTexCoord2f(u, v+dv); glVertex3f(x-.5*w, y-.5*h, 0.);\ 169 glEnd(); } while (0) 170 171 /** Draw a texture centered on the current point, at a given size. 172 *@param iTexture the texture 173 *@param w width 174 *@param h height 175 */ 176 #define _cairo_dock_apply_texture_at_size(iTexture, w, h) do { \ 177 glBindTexture (GL_TEXTURE_2D, iTexture);\ 178 _cairo_dock_apply_current_texture_at_size (w, h); } while (0) 179 180 /** Apply a texture centered on the current point and at the given scale. 181 *@param iTexture the texture 182 */ 183 #define _cairo_dock_apply_texture(iTexture) _cairo_dock_apply_texture_at_size (iTexture, 1, 1) 184 185 /** Draw a texture centered on the current point, at a given size, and with a given transparency. 186 *@param iTexture the texture 187 *@param w width 188 *@param h height 189 *@param fAlpha the transparency, between 0 and 1. 190 */ 191 #define _cairo_dock_apply_texture_at_size_with_alpha(iTexture, w, h, fAlpha) do { \ 192 _cairo_dock_set_alpha (fAlpha);\ 193 _cairo_dock_apply_texture_at_size (iTexture, w, h); } while (0) 194 195 #define cairo_dock_apply_texture _cairo_dock_apply_texture 196 #define cairo_dock_apply_texture_at_size _cairo_dock_apply_texture_at_size 197 void cairo_dock_draw_texture_with_alpha (GLuint iTexture, int iWidth, int iHeight, double fAlpha); 198 void cairo_dock_draw_texture (GLuint iTexture, int iWidth, int iHeight); 199 200 void cairo_dock_apply_icon_texture (Icon *pIcon); 201 void cairo_dock_apply_icon_texture_at_current_size (Icon *pIcon, GldiContainer *pContainer); 202 void cairo_dock_draw_icon_texture (Icon *pIcon, GldiContainer *pContainer); 203 204 205 G_END_DECLS 206 #endif 207