Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void displayText(string text, double centerX, double centerY, double widthDiv2, double heightDiv2, string font, SDL_Color color)
- {
- SDL_Surface *surface;
- if(texts.find(text) == texts.end())
- {
- //initializeText(text, text, font, color);
- //surface = TTF_RenderUTF8_Blended(fonts[font], text.c_str(), color);
- surface = TTF_RenderText_Blended(fonts[font], text.c_str(), color);
- //texts[text] = surface;
- }
- else
- {
- surface = texts[text];
- }
- surface = flipSurface(surface);
- GLuint textTexture;
- glGenTextures(1, &textTexture);
- glBindTexture(GL_TEXTURE_2D, textTexture);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- GLenum codagePixel;
- if(surface->format->Rmask == 0x000000ff)
- codagePixel = GL_RGBA;
- else
- {
- #ifndef GL_BGRA
- #define GL_BGRA 0x80E1
- #endif
- codagePixel = GL_BGRA;
- }
- if(widthDiv2 == -1) // Using by chat system
- {
- double textWidthDiv2 = surface->w / 4, textHeight = surface->h, textHeightDiv2 = textHeight / 2;
- centerX += textWidthDiv2;
- centerY += textHeightDiv2 + heightDiv2 * textHeight;
- widthDiv2 = textWidthDiv2;
- heightDiv2 = textHeightDiv2;
- }
- glTexImage2D(GL_TEXTURE_2D, 0, 4, surface->w, surface->h, 0, codagePixel, GL_UNSIGNED_BYTE, surface->pixels);
- double winW2 = getWindowWidthDiv2();
- double winH2 = getWindowHeightDiv2();
- float vertices[] = {(float)((centerX - widthDiv2) / winW2 - 1), (float)((centerY - heightDiv2) / winH2 - 1), 0, (float)((centerX + widthDiv2) / winW2 - 1), (float)((centerY - heightDiv2) / winH2 - 1), 0, (float)((centerX + widthDiv2) / winW2 - 1), (float)((centerY + heightDiv2) / winH2 - 1), 0,
- (float)((centerX - widthDiv2) / winW2 - 1), (float)((centerY - heightDiv2) / winH2 - 1), 0, (float)((centerX - widthDiv2) / winW2 - 1), (float)((centerY + heightDiv2) / winH2 - 1), 0, (float)((centerX + widthDiv2) / winW2 - 1), (float)((centerY + heightDiv2) / winH2 - 1), 0};
- float texCoord[] = {0, 0, 1, 0, 1, 1,
- 0, 0, 0, 1, 1, 1};
- textShader.use();
- glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vertices);
- glEnableVertexAttribArray(0);
- glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, texCoord);
- glEnableVertexAttribArray(1);
- //Set color
- textShader.setVec4("color", glm::vec4(color.r / 255.0f, color.g / 255.0f, color.b / 255.0f, color.a / 255.0f));
- glDrawArrays(GL_TRIANGLES, 0, 6);
- glBindTexture(GL_TEXTURE_2D, 0);
- glDisableVertexAttribArray(1);
- glDisableVertexAttribArray(0);
- glUseProgram(0);
- SDL_FreeSurface(surface);
- glDeleteTextures(1, &textTexture);
- }
- void displayText(unsigned char nb, double centerX, double centerY, double widthDiv2, double heightDiv2, string font, SDL_Color color)
- {
- displayText(convertNbToStr(nb), centerX, centerY, widthDiv2, heightDiv2, font, color);
- }
- void displayText(GLuint textTexture, double centerX, double centerY, double widthDiv2, double heightDiv2, SDL_Color color)
- {
- glBindTexture(GL_TEXTURE_2D, textTexture);
- if(widthDiv2 == -1)
- {
- GLint height, width;
- glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height);
- glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
- widthDiv2 = width / 2;
- heightDiv2 = height / 2;
- }
- double winW2 = getWindowWidthDiv2();
- double winH2 = getWindowHeightDiv2();
- float vertices[] = {(float)((centerX - widthDiv2) / winW2 - 1), (float)((centerY - heightDiv2) / winH2 - 1), 0, (float)((centerX + widthDiv2) / winW2 - 1), (float)((centerY - heightDiv2) / winH2 - 1), 0, (float)((centerX + widthDiv2) / winW2 - 1), (float)((centerY + heightDiv2) / winH2 - 1), 0,
- (float)((centerX - widthDiv2) / winW2 - 1), (float)((centerY - heightDiv2) / winH2 - 1), 0, (float)((centerX - widthDiv2) / winW2 - 1), (float)((centerY + heightDiv2) / winH2 - 1), 0, (float)((centerX + widthDiv2) / winW2 - 1), (float)((centerY + heightDiv2) / winH2 - 1), 0};
- float texCoord[] = {0, 0, 1, 0, 1, 1,
- 0, 0, 0, 1, 1, 1};
- textShader.use();
- glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vertices);
- glEnableVertexAttribArray(0);
- glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, texCoord);
- glEnableVertexAttribArray(1);
- //Set color
- textShader.setVec4("color", glm::vec4(color.r / 255.0f, color.g / 255.0f, color.b / 255.0f, color.a / 255.0f));
- glDrawArrays(GL_TRIANGLES, 0, 6);
- glBindTexture(GL_TEXTURE_2D, 0);
- glDisableVertexAttribArray(1);
- glDisableVertexAttribArray(0);
- glUseProgram(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement