void MapRenderer::renderOrthoFrontObjects(std::vector<Renderable> &r) { short int i; short int j; Rect dest; std::vector<Renderable>::iterator r_cursor = r.begin(); std::vector<Renderable>::iterator r_end = r.end(); const Point upperleft = floor(screen_to_map(0, 0, shakycam.x, shakycam.y)); short int startj = std::max(0, upperleft.y); short int starti = std::max(0, upperleft.x); const short max_tiles_width = std::min(w, static_cast<short int>(starti + (VIEW_W / TILE_W) + 2 * tset.max_size_x)); const short max_tiles_height = std::min(h, static_cast<short int>(startj + (VIEW_H / TILE_H) + 2 * tset.max_size_y)); while (r_cursor != r_end && (int)(r_cursor->map_pos.y) < startj) ++r_cursor; if (index_objectlayer >= layers.size()) return; maprow *objectlayer = layers[index_objectlayer]; for (j = startj; j < max_tiles_height; j++) { Point p = map_to_screen(starti, j, shakycam.x, shakycam.y); p = center_tile(p); for (i = starti; i<max_tiles_width; i++) { if (const unsigned short current_tile = objectlayer[i][j]) { dest.x = p.x - tset.tiles[current_tile].offset.x; dest.y = p.y - tset.tiles[current_tile].offset.y; tset.tiles[current_tile].tile->setDest(dest); render_device->render(tset.tiles[current_tile].tile); } p.x += TILE_W; while (r_cursor != r_end && (int)(r_cursor->map_pos.y) == j && (int)(r_cursor->map_pos.x) < i) // implicit floor ++r_cursor; // some renderable entities go in this layer while (r_cursor != r_end && (int)(r_cursor->map_pos.y) == j && (int)(r_cursor->map_pos.x) == i) // implicit floor drawRenderable(r_cursor++); } while (r_cursor != r_end && (int)(r_cursor->map_pos.y) <= j) // implicit floor ++r_cursor; } }
void Renderer::paintGL(){ glClear(GL_COLOR_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT); glViewport(0, 0, width(), height()); GLuint currentProgramID = -1; for(GLuint i = 0; i < numRenderables; i++){ Renderable& r = renderables[i]; if(r.progID != currentProgramID){ glUseProgram(r.progID); currentProgramID = r.progID; } drawRenderable(&r, cameraPosition); } //glReadBuffer(GL_FRONT); //int numPixels = width() * height(); //GLfloat* pixels = new GLfloat[numPixels * 3]; //glReadPixels(0, 0, width(), height(), GL_RGB, GL_FLOAT, pixels); //qDebug() << pixels[0]; }
void MapRenderer::renderOrthoBackObjects(std::vector<Renderable> &r) { // some renderables are drawn above the background and below the objects std::vector<Renderable>::iterator it; for (it = r.begin(); it != r.end(); ++it) drawRenderable(it); }
void MapRenderer::renderIsoFrontObjects(std::vector<Renderable> &r) { Rect dest; const Point upperleft = floor(screen_to_map(0, 0, shakycam.x, shakycam.y)); const int_fast16_t max_tiles_width = (VIEW_W / TILE_W) + 2 * tset.max_size_x; const int_fast16_t max_tiles_height = ((VIEW_H / TILE_H) + 2 * tset.max_size_y)*2; std::vector<Renderable>::iterator r_cursor = r.begin(); std::vector<Renderable>::iterator r_end = r.end(); // object layer int_fast16_t j = upperleft.y - tset.max_size_y + tset.max_size_x; int_fast16_t i = upperleft.x - tset.max_size_y - tset.max_size_x; while (r_cursor != r_end && ((int)(r_cursor->map_pos.x) + (int)(r_cursor->map_pos.y) < i + j || (int)(r_cursor->map_pos.x) < i)) // implicit floor ++r_cursor; if (index_objectlayer >= layers.size()) return; maprow *objectlayer = layers[index_objectlayer]; for (uint_fast16_t y = max_tiles_height ; y; --y) { int_fast16_t tiles_width = 0; // make sure the isometric corners are not rendered: if (i < -1) { j += i + 1; tiles_width -= i + 1; i = -1; } const int_fast16_t d = j - h; if (d >= 0) { j -= d; tiles_width += d; i += d; } const int_fast16_t j_end = std::max(static_cast<int_fast16_t>(j+i-w+1), std::max(static_cast<int_fast16_t>(j - max_tiles_width), static_cast<int_fast16_t>(0))); // draw one horizontal line Point p = map_to_screen(float(i), float(j), shakycam.x, shakycam.y); p = center_tile(p); while (j > j_end) { --j; ++i; ++tiles_width; p.x += TILE_W; if (const uint_fast16_t current_tile = objectlayer[i][j]) { dest.x = p.x - tset.tiles[current_tile].offset.x; dest.y = p.y - tset.tiles[current_tile].offset.y; tset.tiles[current_tile].tile->setDest(dest); render_device->render(tset.tiles[current_tile].tile); } // some renderable entities go in this layer while (r_cursor != r_end && ((int)r_cursor->map_pos.x == i && (int)r_cursor->map_pos.y == j)) { // implicit floor by int cast drawRenderable(r_cursor); ++r_cursor; } } j += tiles_width; i -= tiles_width; if (y % 2) i++; else j++; while (r_cursor != r_end && ((int)r_cursor->map_pos.x + (int)r_cursor->map_pos.y < i + j || (int)r_cursor->map_pos.x <= i)) // implicit floor by int cast ++r_cursor; } }
void MapRenderer::renderIsoBackObjects(std::vector<Renderable> &r) { std::vector<Renderable>::iterator it; for (it = r.begin(); it != r.end(); ++it) drawRenderable(it); }