Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void renderEvent()
- {
- // TODO: optimise opengl's options when needed (first initialize when changing gui screen)
- size();
- windowInitialWidth = windowWidth;
- windowInitialHeight = windowHeight;
- font = TTF_OpenFont(string(styles + name + ".ttf").c_str(), 100);
- text = TTF_RenderText_Blended(font, nameUp.c_str(), {255, 255, 255});
- glEnable(GL_CULL_FACE);
- glCullFace(GL_BACK);
- glFrontFace(GL_CCW);
- glClearColor(0, 0, 0, 0);
- glViewport(0, 0, windowWidth, windowHeight);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(70, (GLdouble)windowWidth / (GLdouble)windowHeight, 0.1, 1000);
- SDL_GL_CreateContext(screen);
- gluOrtho2D(0, (GLdouble)windowWidth, 0, (GLdouble)windowHeight);
- glDisable(GL_DEPTH_TEST);
- glEnable(GL_TEXTURE_2D);
- glClear(GL_COLOR_BUFFER_BIT);
- img = loadTexture(string(pictures + "background.jpg").c_str());
- while(1)
- for(int frame = 0; frame < fps; frame++)
- {
- renderScreen();
- SDL_Delay(1000 / fps);
- camera->animate(1000 / fps);
- }
- }
- void renderScreen()
- {
- if(rendering)
- return;
- rendering = true;
- if(!game)
- {
- glBindTexture(GL_TEXTURE_2D, img);
- glBegin(GL_QUADS);
- glTexCoord2d(0, 0); glVertex2f(0, 0);
- glTexCoord2d(0, 1); glVertex2f(0, windowHeight);
- glTexCoord2d(1, 1); glVertex2f(windowWidth, windowHeight);
- glTexCoord2d(1, 0); glVertex2f(windowWidth, 0);
- glEnd();
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- GLuint textureTexte;
- glGenTextures(1, &textureTexte);
- glBindTexture(GL_TEXTURE_2D, textureTexte);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- GLenum codagePixel;
- if(text->format->Rmask == 0x000000ff)
- codagePixel = GL_RGBA;
- else
- {
- #ifndef GL_BGRA
- #define GL_BGRA 0x80E1
- #endif
- codagePixel = GL_BGRA;
- }
- glTexImage2D(GL_TEXTURE_2D, 0, 4, text->w, text->h, 0, codagePixel, GL_UNSIGNED_BYTE, text->pixels);
- glBegin(GL_QUADS);
- glTexCoord2i(0, 0); glVertex2i(windowWidth/2 - resizeWidth / 1.6, windowHeight - resizeHeight / 0.85 + resizeHeight);
- glTexCoord2i(0, 1); glVertex2i(windowWidth/2 - resizeWidth / 1.6, windowHeight - resizeHeight / 0.85 - resizeHeight);
- glTexCoord2i(1, 1); glVertex2i(windowWidth/2 + resizeWidth / 1.6, windowHeight - resizeHeight / 0.85 - resizeHeight);
- glTexCoord2i(1, 0); glVertex2i(windowWidth/2 + resizeWidth / 1.6, windowHeight - resizeHeight / 0.85 + resizeHeight);
- glEnd();
- glFlush();
- SDL_GL_SwapWindow(screen);
- }
- else
- {
- if(first)
- {
- SDL_GL_CreateContext(screen);
- glLoadIdentity();
- glMatrixMode(GL_PROJECTION);
- gluPerspective(70, (GLdouble)windowWidth / (GLdouble)windowHeight, 0.1, 1000);
- glEnable(GL_DEPTH_TEST);
- glEnable(GL_TEXTURE_2D);
- initializeMapRender();
- first = false;
- }
- glEnable(GL_CULL_FACE);
- glCullFace(GL_BACK);
- glFrontFace(GL_CCW);
- glClearColor(0, 0, 0, 0);
- glViewport(0, 0, 1365, 704);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(70.0, (GLdouble)windowWidth / (GLdouble)windowHeight, 0.1, 1000.0);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glEnable(GL_DEPTH_TEST);
- glMatrixMode( GL_MODELVIEW );
- glLoadIdentity();
- glEnable(GL_TEXTURE_2D);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- camera->look();
- renderMap();
- drawAxis();
- renderChat();
- glFlush();
- SDL_GL_SwapWindow(screen);
- }
- rendering = false;
- }
- void drawText(string message, int a)
- {
- SDL_Surface* text = TTF_RenderText_Blended(arial, message.c_str(), {255, 255, 255});
- GLuint textTexture;
- glGenTextures(1, &textTexture);
- glBindTexture(GL_TEXTURE_2D, textTexture);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- GLenum pixelCode = GL_RGBA;
- glTexImage2D(GL_TEXTURE_2D, 0, 4, text->w, text->h, 0, pixelCode, GL_UNSIGNED_BYTE, text->pixels);
- double width = text->w, height = text->h, posX = width / 2 + windowWidth / 100, posY = height / 2 + windowHeight / 100 + height * (a + 1);
- resize(width, height);
- SDL_FreeSurface(text);
- glBindTexture(GL_TEXTURE_2D, textTexture);
- glBegin(GL_QUADS);
- glTexCoord2i(0, 0); glVertex2i(posX - resizeWidth - patch, posY + resizeHeight);
- glTexCoord2i(0, 1); glVertex2i(posX - resizeWidth - patch, posY - resizeHeight);
- glTexCoord2i(1, 1); glVertex2i(posX + resizeWidth - patch, posY - resizeHeight);
- glTexCoord2i(1, 0); glVertex2i(posX + resizeWidth - patch, posY + resizeHeight);
- glEnd();
- }
- void prepareChat()
- {
- glPushMatrix();
- glLoadIdentity();
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glLoadIdentity();
- gluOrtho2D(0.0, (GLdouble)1365, 0.0, (GLdouble)704);
- glDisable(GL_DEPTH_TEST);
- glEnable(GL_TEXTURE_2D);
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement