/** * render skybox */ void renderWithProgram(GLSL::mat4 &p_pvm_matrix) { // CGlStateDisable depth_test(GL_DEPTH_TEST); CGlErrorCheck(); program.use(); pvm_matrix_uniform.set(p_pvm_matrix); vertex_buffer.bind(); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nullptr); glEnableVertexAttribArray(0); texture_cube_map.bind(); #if 0 CGlErrorCheck(); glDrawArrays(GL_TRIANGLES, 0, 3); CGlErrorCheck(); #else index_buffer.bind(); CGlErrorCheck(); glDrawElements(GL_TRIANGLE_STRIP, 20, GL_UNSIGNED_BYTE, 0); index_buffer.unbind(); #endif texture_cube_map.unbind(); glDisableVertexAttribArray(0); vertex_buffer.unbind(); program.disable(); CGlErrorCheck(); }
void cv::render(const GlTexture& tex, Rect_<double> wndRect, Rect_<double> texRect) { #ifndef HAVE_OPENGL (void)tex; (void)wndRect; (void)texRect; throw_nogl; #else if (!tex.empty()) { tex.bind(); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glBegin(GL_QUADS); glTexCoord2d(texRect.x, texRect.y); glVertex2d(wndRect.x, wndRect.y); glTexCoord2d(texRect.x, texRect.y + texRect.height); glVertex2d(wndRect.x, (wndRect.y + wndRect.height)); glTexCoord2d(texRect.x + texRect.width, texRect.y + texRect.height); glVertex2d(wndRect.x + wndRect.width, (wndRect.y + wndRect.height)); glTexCoord2d(texRect.x + texRect.width, texRect.y); glVertex2d(wndRect.x + wndRect.width, wndRect.y); glEnd(); CV_CheckGlError(); tex.unbind(); } #endif }
/** * initialize skybox texture with files give as parameters */ void initWithTextures( const char *file_pos_x, const char *file_neg_x, const char *file_pos_y, const char *file_neg_y, const char *file_pos_z, const char *file_neg_z ) { texture_cube_map.bind(); texture_cube_map.loadFromFile(file_pos_x, GL_TEXTURE_CUBE_MAP_POSITIVE_X); texture_cube_map.loadFromFile(file_neg_x, GL_TEXTURE_CUBE_MAP_NEGATIVE_X); texture_cube_map.loadFromFile(file_pos_y, GL_TEXTURE_CUBE_MAP_POSITIVE_Y); texture_cube_map.loadFromFile(file_neg_y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y); texture_cube_map.loadFromFile(file_pos_z, GL_TEXTURE_CUBE_MAP_POSITIVE_Z); texture_cube_map.loadFromFile(file_neg_z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z); texture_cube_map.unbind(); CError_Append(texture_cube_map); }
void vis_render() { const PlaneData *ro_visData; double aspect_ratio = 0; simulation->vis_get_vis_data_array(&ro_visData, &aspect_ratio); PlaneData &visData = (PlaneData&)*ro_visData; if (glTexture == nullptr) { glTexture = new GlTexture(GL_TEXTURE_2D, GL_RED, GL_RED, GL_UNSIGNED_BYTE); glTexture->bind(); glTexture->resize(visData.planeDataConfig->physical_data_size[0], visData.planeDataConfig->physical_data_size[1]); glTexture->unbind(); texture_data = new unsigned char[visData.planeDataConfig->physical_array_data_number_of_elements]; } visData.request_data_physical(); vis_min = visData.reduce_min(); vis_max = visData.reduce_max(); vis_max = std::max(vis_max, vis_min+1e-20); //< avoid numerical issues if min == max double real_delta = vis_max-vis_min; // vis_min -= real_delta*0.03; // vis_max += real_delta*0.03; double inv_delta = 1.0/real_delta; #pragma omp parallel for OPENMP_PAR_SIMD for (std::size_t i = 0; i < visData.planeDataConfig->physical_array_data_number_of_elements; i++) { double value = (visData.physical_space_data[i]-vis_min)*inv_delta; value *= 255.0; texture_data[i] = (unsigned char)std::min(255.0, std::max(0.0, value)); } glTexture->bind(); glTexture->setData(texture_data); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); double scale_x = 1.0; double scale_y = aspect_ratio; if (aspect_ratio > 1.0) { scale_x /= aspect_ratio; scale_y = 1.0; } visualizationEngine->engineState->commonShaderPrograms.shaderTexturizeRainbowmap.use(); visualizationEngine->engineState->commonShaderPrograms.shaderTexturizeRainbowmap.pvm_matrix_uniform.set( visualizationEngine->engineState->matrices.pvm*GLSL::scale((float)scale_x, (float)scale_y, (float)1.0) ); glDrawQuad->render(); visualizationEngine->engineState->commonShaderPrograms.shaderTexturizeRainbowmap.disable(); glTexture->unbind(); if (hud_visible) { glFreeType->viewportChanged(visualizationEngine->renderWindow->window_width, visualizationEngine->renderWindow->window_height); std::string status_string = simulation->vis_get_status_string(); std::replace(status_string.begin(), status_string.end(), ',', '\n'); glFreeType->setPosition(10, visualizationEngine->renderWindow->window_height-16); glFreeType->renderString(status_string.c_str()); visSweetHUD->render(); } // execute simulation time step simulation->vis_post_frame_processing(sim_runs_per_frame); }