ManaPlus
Functions
safeopenglgraphics.cpp File Reference

(986a3bf)

#include "render/safeopenglgraphics.h"
#include "resources/imagerect.h"
#include "resources/safeopenglimagehelper.h"
#include "resources/image/image.h"
#include "utils/sdlcheckutils.h"
#include "debug.h"
#include "render/graphics_drawImageRect.hpp"
#include "render/graphics_calcImageRect.hpp"

Go to the source code of this file.

Functions

static void drawQuad (const Image *image, const int srcX, const int srcY, const int dstX, const int dstY, const int width, const int height) A_INLINE
 
static void drawRescaledQuad (const Image *const image, const int srcX, const int srcY, const int dstX, const int dstY, const int width, const int height, const int desiredWidth, const int desiredHeight) A_INLINE
 

Function Documentation

◆ drawQuad()

static void drawQuad ( const Image image,
const int  srcX,
const int  srcY,
const int  dstX,
const int  dstY,
const int  width,
const int  height 
)
inlinestatic

Definition at line 91 of file safeopenglgraphics.cpp.

98 {
99  if (SafeOpenGLImageHelper::mTextureType == GL_TEXTURE_2D)
100  {
101  const float tw = static_cast<float>(image->mTexWidth);
102  const float th = static_cast<float>(image->mTexHeight);
103  // Find OpenGL normalized texture coordinates.
104  const float texX1 = static_cast<float>(srcX) / tw;
105  const float texY1 = static_cast<float>(srcY) / th;
106  const float texX2 = static_cast<float>(srcX + width) / tw;
107  const float texY2 = static_cast<float>(srcY + height) / th;
108 
109  glTexCoord2f(texX1, texY1);
110  glVertex2i(dstX, dstY);
111  glTexCoord2f(texX2, texY1);
112  glVertex2i(dstX + width, dstY);
113  glTexCoord2f(texX2, texY2);
114  glVertex2i(dstX + width, dstY + height);
115  glTexCoord2f(texX1, texY2);
116  glVertex2i(dstX, dstY + height);
117  }
118  else
119  {
120  glTexCoord2i(srcX, srcY);
121  glVertex2i(dstX, dstY);
122  glTexCoord2i(srcX + width, srcY);
123  glVertex2i(dstX + width, dstY);
124  glTexCoord2i(srcX + width, srcY + height);
125  glVertex2i(dstX + width, dstY + height);
126  glTexCoord2i(srcX, srcY + height);
127  glVertex2i(dstX, dstY + height);
128  }
129 }

References SafeOpenGLImageHelper::mTextureType.

◆ drawRescaledQuad()

static void drawRescaledQuad ( const Image *const  image,
const int  srcX,
const int  srcY,
const int  dstX,
const int  dstY,
const int  width,
const int  height,
const int  desiredWidth,
const int  desiredHeight 
)
inlinestatic

Definition at line 139 of file safeopenglgraphics.cpp.

145 {
146  if (SafeOpenGLImageHelper::mTextureType == GL_TEXTURE_2D)
147  {
148  const float tw = static_cast<float>(image->mTexWidth);
149  const float th = static_cast<float>(image->mTexHeight);
150  // Find OpenGL normalized texture coordinates.
151  const float texX1 = static_cast<float>(srcX) / tw;
152  const float texY1 = static_cast<float>(srcY) / th;
153  const float texX2 = static_cast<float>(srcX + width) / tw;
154  const float texY2 = static_cast<float>(srcY + height) / th;
155 
156  glTexCoord2f(texX1, texY1);
157  glVertex2i(dstX, dstY);
158  glTexCoord2f(texX2, texY1);
159  glVertex2i(dstX + desiredWidth, dstY);
160  glTexCoord2f(texX2, texY2);
161  glVertex2i(dstX + desiredWidth, dstY + desiredHeight);
162  glTexCoord2f(texX1, texY2);
163  glVertex2i(dstX, dstY + desiredHeight);
164  }
165  else
166  {
167  glTexCoord2i(srcX, srcY);
168  glVertex2i(dstX, dstY);
169  glTexCoord2i(srcX + width, srcY);
170  glVertex2i(dstX + desiredWidth, dstY);
171  glTexCoord2i(srcX + width, srcY + height);
172  glVertex2i(dstX + desiredWidth, dstY + desiredHeight);
173  glTexCoord2i(srcX, srcY + height);
174  glVertex2i(dstX, dstY + desiredHeight);
175  }
176 }

References SafeOpenGLImageHelper::mTextureType.