virtual void reshape_gl() { // Allocate array memory allocate(gps.dimx * gps.dimy); // Initialize the vertex array int tile = 0; for (GLfloat x = 0; x < gps.dimx; x++) for (GLfloat y = 0; y < gps.dimy; y++, tile++) write_tile_vertexes(x, y, vertexes + 6*2*tile); // Setup invariant state glEnableClientState(GL_COLOR_ARRAY); /// Set up our coordinate system if (forced_steps + zoom_steps == 0 && init.display.flag.has_flag(INIT_DISPLAY_FLAG_BLACK_SPACE)) { int size_x = gps.dimx * dispx, size_y = gps.dimy * dispy; int off_x = (screen->w - size_x) / 2, off_y = (screen->h - size_y) / 2; glViewport(off_x, off_y, size_x, size_y); } glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, gps.dimx, gps.dimy, 0); }
void update_tile(int x, int y) { write_tile_vertexes(x, y, vertexes + tile_count * 6 * 2); write_tile_arrays(x, y, fg + tile_count * 6 * 4, bg + tile_count * 6 * 4, tex + tile_count * 6 * 2); tile_count++; }
void renderer_cool::reshape_graphics() { float tsx = (float)size_x / gps->dimx, tsy = (float)size_y / gps->dimy; int32_t w = gps->dimx, h = gps->dimy; int cx = *df::global::window_x + gdimx / 2; int cy = *df::global::window_y + gdimy / 2; df::viewscreen *ws = Gui::getCurViewscreen(); if (df::viewscreen_dwarfmodest::_identity.is_direct_instance(ws)) { gsize_x = (size_x - tsx * (gmenu_w + 1 + 1)); gsize_y = (size_y - tsy * 2); goff_x = off_x + roundf(tsx); goff_y = off_y + roundf(tsy); } else //Adv. mode { *out2 << "reshape_graphics" << std::endl; gsize_x = size_x; gsize_y = size_y; goff_x = off_x; goff_y = goff_y_gl = off_y; } float dimx = std::min(gsize_x / gdispx, 256.0f); float dimy = std::min(gsize_y / gdispy, 256.0f); gdimx = ceilf(dimx); gdimy = ceilf(dimy); gdimxfull = floorf(dimx); gdimyfull = floorf(dimy); if (df::viewscreen_dwarfmodest::_identity.is_direct_instance(ws)) goff_y_gl = goff_y - (gdimy == gdimyfull ? 0 : roundf(gdispy - (gsize_y - gdispy * gdimyfull))); *df::global::window_x = std::max(0, cx - gdimx / 2); *df::global::window_y = std::max(0, cy - gdimy / 2); int tiles = gdimx * gdimy; // Recreate tile buffers allocate_buffers(tiles); // Recreate OpenGL buffers gvertexes = (GLfloat*)realloc(gvertexes, sizeof(GLfloat) * tiles * 2 * 6); gfg = (GLfloat*)realloc(gfg, sizeof(GLfloat) * tiles * 4 * 6); gbg = (GLfloat*)realloc(gbg, sizeof(GLfloat) * tiles * 4 * 6); gtex = (GLfloat*)realloc(gtex, sizeof(GLfloat) * tiles * 2 * 6); // Initialise vertex coords int tile = 0; for (GLfloat x = 0; x < gdimx; x++) for (GLfloat y = 0; y < gdimy; y++, tile++) write_tile_vertexes(x, y, gvertexes + 6 * 2 * tile); needs_full_update = true; }
void update_tile(int x, int y) { write_tile_vertexes(x, y, vertexes + head * 6 * 2); write_tile_arrays(x, y, fg + head * 6 * 4, bg + head * 6 * 4, tex + head * 6 * 2); head = (head + 1) % buffersz; current_erasz++; sum_erasz++; if (head == tail) { gamelog << "Expanding partial-printing buffer" << endl; // Buffer is full, expand it. renderer_opengl::allocate(buffersz * 2); // Move the tail to the end of the newly allocated space tail += buffersz; memmove(vertexes + tail * 6 * 4, fg + head * 6 * 2, sizeof(GLfloat) * 6 * 2 * (buffersz - head)); memmove(fg + tail * 6 * 4, fg + head * 6 * 4, sizeof(GLfloat) * 6 * 4 * (buffersz - head)); memmove(bg + tail * 6 * 4, fg + head * 6 * 4, sizeof(GLfloat) * 6 * 4 * (buffersz - head)); memmove(tex + tail * 6 * 4, fg + head * 6 * 2, sizeof(GLfloat) * 6 * 2 * (buffersz - head)); // And finish. buffersz *= 2; } }