void OpenGLImageHelper::copySurfaceToImage(const Image *const image, const int x, const int y, SDL_Surface *surface) const { if (!surface || !image) return; SDL_Surface *const oldSurface = surface; surface = convertSurface(surface, surface->w, surface->h); if (!surface) return; // +++ probably need combine // mglTextureSubImage2D and mglTextureSubImage2DEXT if (mglTextureSubImage2D) { mglTextureSubImage2D(image->mGLImage, 0, x, y, surface->w, surface->h, GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels); } else { mglTextureSubImage2DEXT(image->mGLImage, mTextureType, 0, x, y, surface->w, surface->h, GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels); } if (surface != oldSurface) MSDL_FreeSurface(surface); }
//class ImageFromFile ImageFromFile::ImageFromFile(SDL_Renderer* renderer, string imageFile, int centerX, int centerY) { SDL_Surface* surface; surface = IMG_Load(imageFile.c_str()); convertSurface(renderer, surface); centerCoordX = centerX; centerCoordY = centerY; }
//Class ImageFromText ImageFromText::ImageFromText(SDL_Renderer* renderer, string textIn, SDL_Color colorIn, int fontSize, string fontIn) { font = TTF_OpenFont(fontIn.c_str(), fontSize); color = colorIn; text = textIn; SDL_Surface* surface; surface = TTF_RenderUTF8_Blended(font, text.c_str(), color); convertSurface(renderer, surface); }
void OpenGLImageHelper::copySurfaceToImage(const Image *const image, const int x, const int y, SDL_Surface *surface) const { if (!surface || !image) return; SDL_Surface *const oldSurface = surface; surface = convertSurface(surface, surface->w, surface->h); mglTextureSubImage2D(image->mGLImage, mTextureType, 0, x, y, surface->w, surface->h, GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels); if (surface != oldSurface) MSDL_FreeSurface(surface); }
Image *OpenGLImageHelper::glLoad(SDL_Surface *tmpImage, int width, int height) { if (!tmpImage) return nullptr; BLOCK_START("OpenGLImageHelper::glLoad") // Flush current error flag. graphicsManager.getLastError(); if (!width) width = tmpImage->w; if (!height) height = tmpImage->h; SDL_Surface *oldImage = tmpImage; tmpImage = convertSurface(tmpImage, width, height); const int realWidth = tmpImage->w; const int realHeight = tmpImage->h; const GLuint texture = getNewTexture(); bindTexture(texture); if (SDL_MUSTLOCK(tmpImage)) SDL_LockSurface(tmpImage); if (mUseOpenGL != RENDER_MODERN_OPENGL && mUseOpenGL != RENDER_GLES_OPENGL) glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); if (!mUseTextureSampler) { if (mBlur) { glTexParameteri(mTextureType, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(mTextureType, GL_TEXTURE_MAG_FILTER, GL_LINEAR); } else { glTexParameteri(mTextureType, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(mTextureType, GL_TEXTURE_MAG_FILTER, GL_NEAREST); } } #ifndef ANDROID glTexParameteri(mTextureType, GL_TEXTURE_MAX_LEVEL, 0); #endif glTexImage2D(mTextureType, 0, mInternalTextureType, tmpImage->w, tmpImage->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, tmpImage->pixels); #ifdef DEBUG_OPENGL // disabled for now, because debugger can't show it // if (isGLNotNull(mglLabelObject)) // { // const char *const text = "image text"; // mglLabelObject(GL_TEXTURE, texture, strlen(text), text); // } #endif /* GLint compressed; glGetTexLevelParameteriv(mTextureType, 0, GL_TEXTURE_COMPRESSED_ARB, &compressed); if (compressed) logger->log("image compressed"); else logger->log("image not compressed"); */ #ifdef DEBUG_OPENGL_LEAKS textures_count ++; #endif if (SDL_MUSTLOCK(tmpImage)) SDL_UnlockSurface(tmpImage); if (oldImage != tmpImage) MSDL_FreeSurface(tmpImage); GLenum error = graphicsManager.getLastError(); if (error) { std::string errmsg = GraphicsManager::errorToString(error); logger->log("Error: Image GL import failed: %s (%u)", errmsg.c_str(), error); // return nullptr; } BLOCK_END("OpenGLImageHelper::glLoad") return new Image(texture, width, height, realWidth, realHeight); }