void FrameBufferObject::init(unsigned int width, unsigned height) { if (!initialized) { this->width = width; this->height = height; glGenFramebuffersEXT(1, &id); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, id); if(enableDepth) { createDepthBuffer(); initDepthBuffer(); //choice between rendering depth into a texture or a renderbuffer if(depthTexture) glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, depthTextureID, 0); else glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depthTextureID); } if(enableColor) { createColorBuffer(); initColorBuffer(); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, colorTextureID, 0); } glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_defaultWindowFramebufferID); if(enableColor) { glDrawBuffer(GL_BACK); glReadBuffer(GL_BACK);; } #ifdef _DEBUG checkFBO(); #endif initialized=true; glDisable(GL_TEXTURE_2D); } else setSize(width, height); }
Segregation(int window_width_, int window_height_, int width_, int height_, int num_teams_, double rate_population, double rate_friend_) : window_width(window_width_), window_height(window_height_), width(width_), height(height_), num_teams(num_teams_), rate_friend(rate_friend_), agent_vertex_vbo(0), agent_color_vbo(0), max_num_teams(5), empty(-1), mouse_button(0), translate_x(0), translate_y(0), scale_size(1), pause(false), single(false), fpsLimit(1), fpsCount(0), vsync(1), ticks(0) { if (num_teams > max_num_teams) { std::cerr << "Error: Invalid Number of Teams\n"; std::exit(0); } if (!initGlut()) { std::exit(0); } patch = (float)window_width / width; halfPatch = patch / 2; /* Calculating population */ one_team_population = width * height * rate_population / num_teams; population = one_team_population * num_teams; /* Initializing Parameters */ pos = std::vector< Point<int> >(population, Point<int>()); group = std::vector<int>(population, 0); space = std::vector<int>(width * height, -1);// empty: -1 int agent_id = 0; while (agent_id < population) { int x = mcl::Random::random(width); int y = mcl::Random::random(height); if (space[getOneDimIdx(x, y)] == empty) { pos[agent_id].x = x, pos[agent_id].y = y; space[getOneDimIdx(x, y)] = group[agent_id] = agent_id % num_teams; agent_id++; } } /* Setting Positions on Screen */ fp[0].x = halfPatch; fp[0].y = -1 * halfPatch; fp[1].x = -1 * halfPatch; fp[1].y = -1 * halfPatch; fp[2].x = -1 * halfPatch; fp[2].y = halfPatch; fp[3].x = halfPatch; fp[3].y = halfPatch; /* Setting Color */ color_set = std::vector<mcl::Color::ColorElement>(max_num_teams); color_set[0].value = mcl::Color::Red; color_set[1].value = mcl::Color::Green; color_set[2].value = mcl::Color::Yellow; color_set[3].value = mcl::Color::Blue; color_set[4].value = mcl::Color::Orange; createVertexBuffer(); createColorBuffer(); }