Exemplo n.º 1
0
void GLView::handleIdle()
{
    modcounter++;
    if (!paused) world->update();

    //show FPS
    int currentTime = glutGet( GLUT_ELAPSED_TIME );
    frames++;
    if ((currentTime - lastUpdate) >= 1000) {
        std::pair<int,int> num_herbs_carns = world->numHerbCarnivores();
        sprintf( buf, "FPS: %d NumAgents: %d Carnivors: %d Herbivors: %d Epoch: %d", frames, world->numAgents(), num_herbs_carns.second, num_herbs_carns.first, world->epoch() );
        glutSetWindowTitle( buf );
        frames = 0;
        lastUpdate = currentTime;
    }
    if (skipdraw<=0 && draw) {
        clock_t endwait;
        float mult=-0.005*(skipdraw-1); //ugly, ah well
        endwait = clock () + mult * CLOCKS_PER_SEC ;
        while (clock() < endwait) {}
    }

    if (draw) {
        if (skipdraw>0) {
            if (modcounter%skipdraw==0) renderScene();    //increase fps by skipping drawing
        }
        else renderScene(); //we will decrease fps by waiting using clocks
    }

}
Exemplo n.º 2
0
void display()
{
	// Compute the MVP (Model View Projection matrix)
	glm::mat4 ViewTranslate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -Window.TranlationCurrent.y));
	glm::mat4 ViewRotateX = glm::rotate(ViewTranslate, Window.RotationCurrent.y, glm::vec3(1.f, 0.f, 0.f));
	glm::mat4 View = glm::rotate(ViewRotateX, Window.RotationCurrent.x, glm::vec3(0.f, 1.f, 0.f));
	glm::mat4 Model = glm::mat4(1.0f);

	{
		glm::mat4 Projection = glm::perspective(45.0f, float(FRAMEBUFFER_SIZE.x) / float(FRAMEBUFFER_SIZE.y), 0.1f, 100.0f);
		glm::mat4 MVP = Projection * View * Model;

		glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);
		glViewport(0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y);
		renderScene(glm::vec4(0.0f, 0.0f, 0.0f, 1.0f), MVP, Texture2DName);
	}

	{
		glm::mat4 Projection = glm::perspective(45.0f, float(Window.Size.x) / float(Window.Size.y), 0.1f, 100.0f);
		glm::mat4 MVP = Projection * View * Model;

		glBindFramebuffer(GL_FRAMEBUFFER, 0);
		glViewport(0, 0, Window.Size.x, Window.Size.y);
		renderScene(glm::vec4(1.0f, 0.5f, 0.0f, 1.0f), MVP, ColorbufferName);

		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, ColorbufferName);
		glBindSampler(0, SamplerName);
		glGenerateMipmap(GL_TEXTURE_2D);
	}

	glf::checkError("display");
	glf::swapBuffers();
}
Exemplo n.º 3
0
void display()
{
	// Compute the MVP (Model View Projection matrix)
	glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.0f);
	glm::mat4 ViewTranslate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -Window.TranlationCurrent.y));
	glm::mat4 ViewRotateX = glm::rotate(ViewTranslate, Window.RotationCurrent.y, glm::vec3(1.f, 0.f, 0.f));
	glm::mat4 View = glm::rotate(ViewRotateX, Window.RotationCurrent.x, glm::vec3(0.f, 1.f, 0.f));
	glm::mat4 Model = glm::mat4(1.0f);
	glm::mat4 MVP = Projection * View * Model;

	glEnable(GL_SCISSOR_TEST);

	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	glScissor(0, 0, Window.Size.x, Window.Size.y);
	glClear(GL_COLOR_BUFFER_BIT);

	glViewport(0, 0, Window.Size.x, Window.Size.y);
	renderScene(MVP);

	glClearColor(0.0f, 0.5f, 1.0f, 1.0f);
	glScissor(64, 48, 160, 120);
	glClear(GL_COLOR_BUFFER_BIT);

	glViewport(64, 48, 160, 120);
	renderScene(MVP);

	glDisable(GL_SCISSOR_TEST);

	glf::checkError("display");
	glf::swapBuffers();
}
Exemplo n.º 4
0
void GM_Debug::updateScene()
{
	renderScene();
	g_engine->resetClipping();
	desktop.DelayedRemove();
	if (killpopup) {
        delete popup;
        popup = NULL;
        killpopup = false;
        renderScene();
	}
}
void display()
{
	glm::mat4 ViewTranslate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -Window.TranlationCurrent.y));
	glm::mat4 ViewRotateX = glm::rotate(ViewTranslate, Window.RotationCurrent.y, glm::vec3(1.f, 0.f, 0.f));
	glm::mat4 View = glm::rotate(ViewRotateX, Window.RotationCurrent.x, glm::vec3(0.f, 1.f, 0.f));
	glm::mat4 Model = glm::mat4(1.0f);

	glEnable(GL_SCISSOR_TEST);
	glDisable(GL_FRAMEBUFFER_SRGB);
	glScissorIndexed(0, 0, 0, Window.Size.x, Window.Size.y);
	glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]);

	{
		glm::mat4 Projection = glm::perspective(45.0f, float(FRAMEBUFFER_SIZE.x) / float(FRAMEBUFFER_SIZE.y), 0.1f, 100.0f);
		glm::mat4 MVP = Projection * View * Model;

		glViewportIndexedf(0, 0, 0, float(FRAMEBUFFER_SIZE.x), float(FRAMEBUFFER_SIZE.y));
		glDisable(GL_FRAMEBUFFER_SRGB);

		glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);
		glClearBufferfv(GL_COLOR, 0, &glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)[0]);
		renderScene(glm::vec4(0.0f, 0.0f, 0.0f, 1.0f), MVP, Texture2DName);
		glBindFramebuffer(GL_FRAMEBUFFER, 0);
	}

	{
		glm::mat4 Projection = glm::perspective(45.0f, float(Window.Size.x) / float(Window.Size.y), 0.1f, 100.0f);
		glm::mat4 MVP = Projection * View * Model;

		glViewportIndexedfv(0, &glm::vec4(0, 0, Window.Size.x, Window.Size.y)[0]);

		// Correct display
		glScissorIndexed(0, 0, Window.Size.y / 2 - 1, Window.Size.x, Window.Size.y / 2);
		glEnable(GL_FRAMEBUFFER_SRGB);
		glSamplerParameteri(SamplerName, GL_TEXTURE_SRGB_DECODE_EXT, GL_SKIP_DECODE_EXT); // GL_DECODE_EXT 
		renderScene(glm::vec4(1.0f, 0.5f, 0.0f, 1.0f), MVP, ColorbufferName);
		glDisable(GL_FRAMEBUFFER_SRGB);

		// Incorrected display
		glScissorIndexed(0, 0, 0, Window.Size.x, Window.Size.y / 2);
		glEnable(GL_FRAMEBUFFER_SRGB);
		glSamplerParameteri(SamplerName, GL_TEXTURE_SRGB_DECODE_EXT, GL_DECODE_EXT); // GL_DECODE_EXT 
		renderScene(glm::vec4(1.0f, 0.5f, 0.0f, 1.0f), MVP, ColorbufferName);
		glDisable(GL_FRAMEBUFFER_SRGB);
	}

	glf::swapBuffers();
	glf::checkError("display");
}
void display (void)
{
	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glDisable(GL_LIGHTING);
	drawAxis();
	glEnable(GL_LIGHTING);
	glColor3f (1., 0, 0.);
	renderScene();
	float ground[4] = {1,0,0,4};
	myShadowMatrix(ground, position);
	glColor3f (0.5, 0.5, 0.5);
	renderScene();
	glFlush ();
}
Exemplo n.º 7
0
/*Main Loop*/
void mainLoop() {
  double oldTime = glfwGetTime(), oldFrameTime = glfwGetTime();
  double currentTime, deltaFrame;

  while (!glfwWindowShouldClose(window)) {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    /*Delta*/
    currentTime = glfwGetTime();
    delta = (currentTime-oldTime);
    deltaFrame = (currentTime-oldFrameTime);
    nFrames++;

    /* Update scene elements */
    world.update();

    /*Draw*/
    renderReflection();
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    renderScene(true);

    world.camera.calcMovement(keyState);
    world.camera.move(delta, world.sea.seaLevel + 1.0f);

    glfwSwapBuffers(window);
    glfwPollEvents();

    oldTime = currentTime;
  }
}
Exemplo n.º 8
0
void DS_Basic_MRT::buildGBuffers()
{
	HRESULT hr;
	//-- G-Buffsers
	SetRenderTarget SRT(m_pD3DDevice, m_posRT);

	IDirect3DSurface9 *pSurfaceZ = NULL;
	hr = m_posRT_Z->GetSurfaceLevel(0, &pSurfaceZ );

	IDirect3DSurface9 *pSurfaceNormal = NULL;
	hr = m_normalRT->GetSurfaceLevel(0, &pSurfaceNormal );
	
	IDirect3DSurface9 *pSurfaceDiffuse= NULL;
	hr = m_diffuseRT->GetSurfaceLevel(0, &pSurfaceDiffuse );
	
	hr = m_pD3DDevice->SetRenderTarget(1, pSurfaceZ);
	hr = m_pD3DDevice->SetRenderTarget(2, pSurfaceNormal);
	hr = m_pD3DDevice->SetRenderTarget(3, pSurfaceDiffuse);

	pSurfaceZ->Release();
	pSurfaceDiffuse->Release();
	pSurfaceNormal->Release();

	hr = m_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, 0, 1, 0);

	hr = m_pEffect->SetTechnique("init_mrt");
	renderScene();

	hr = m_pD3DDevice->SetRenderTarget(1, NULL);
	hr = m_pD3DDevice->SetRenderTarget(2, NULL);
	hr = m_pD3DDevice->SetRenderTarget(3, NULL);

	//hr = D3DXSaveTextureToFile("D:\\test.dds", D3DXIFF_DDS, m_posRT, NULL);
}
  void draw() {
    glClear(GL_COLOR_BUFFER_BIT);
    gl::MatrixStack & mv = gl::Stacks::modelview();
    gl::MatrixStack & pr = gl::Stacks::projection();

    FOR_EACH_EYE(eye) {
      const PerEyeArg & eyeArgs = eyes[eye];
      frameBuffer.activate();
      glEnable(GL_DEPTH_TEST);
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

      gl::Stacks::with_push(pr, mv, [&]{
        mv.preMultiply(eyeArgs.modelviewOffset);
        pr.preMultiply(eyeArgs.projectionOffset);
        renderScene();
      });

      frameBuffer.deactivate();
      glDisable(GL_DEPTH_TEST);

      viewport(eye);
      distortProgram->use();
      glActiveTexture(GL_TEXTURE1);
      eyeArgs.distortionTexture->bind();
      glActiveTexture(GL_TEXTURE0);
      frameBuffer.color->bind();
      quadGeometry->bindVertexArray();
      quadGeometry->draw();
      gl::VertexArray::unbind();
      gl::Program::clear();
    }
  }
Exemplo n.º 10
0
  void draw() {
    static int frameIndex = 0;
    static ovrPosef eyePoses[2];
    ++frameIndex;
    ovrHmd_GetEyePoses(hmd, frameIndex, eyeOffsets, eyePoses, nullptr);

    ovrHmd_BeginFrame(hmd, frameIndex);
    glEnable(GL_DEPTH_TEST);

    for (int i = 0; i < 2; ++i) {
      ovrEyeType eye = hmd->EyeRenderOrder[i];

      const ovrRecti & vp = textures[eye].Header.RenderViewport;
      eyeFramebuffers[eye]->Bind();
      oglplus::Context::Viewport(vp.Pos.x, vp.Pos.y, vp.Size.w, vp.Size.h);
      Stacks::projection().top() = eyeProjections[eye];

      MatrixStack & mv = Stacks::modelview();
      mv.withPush([&]{
        // Apply the per-eye offset & the head pose
        mv.top() = glm::inverse(ovr::toGlm(eyePoses[eye])) * mv.top();
        renderScene();
      });
    };
    oglplus::DefaultFramebuffer().Bind(oglplus::Framebuffer::Target::Draw);

    ovrHmd_EndFrame(hmd, eyePoses, textures);
  }
Exemplo n.º 11
0
/*Setup a viewport of a first person view from a base.*/
void firstPersonView(float baseRotation, float starRotation, int leftY)
{
    glPushMatrix();
    
    glTranslatef(0.0, 0.0, -2.3);
    /*Rotate on x axis to get the flat ringworld.*/
    glRotatef(-90.0, 1.0, 0.0, 0.0);
    /*Rotate on z to get to a base.*/
    glRotatef(baseRotation, 0.0, 0.0, 1.0);
    
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0f, 700.0f/350.0f, 0.1f, 100.0f);
    glMatrixMode(GL_MODELVIEW);
    glViewport(0, leftY, 700, 350);

    /*Draw the star background perspective.*/
    glPushMatrix();
    glRotatef(starRotation, 0.0, 1.0, 0.0);
    glTranslatef(0.0, 0.0, -2.2);
    drawStarBackground();
    glPopMatrix();

    renderScene();
    glPopMatrix();
}
Exemplo n.º 12
0
MainWindow::MainWindow(QWidget *parent)
    : QWidget(parent)
    , m_rendererPanel(new RendererPanel(this))
{

    setlocale(LC_ALL,"C");
    //omp_set_dynamic(1);
    display.resize(512,512);
    layout = new QHBoxLayout();
    layout->addWidget(&display);

    layout->addWidget(m_rendererPanel);

    mainLayout = new QVBoxLayout();
    renderButton = new QPushButton("Render");
    mainLayout->addLayout(layout);
    mainLayout->addWidget(renderButton);

    setLayout(mainLayout);

    m_image = new Image(512, 512);
    display.setImage(m_image);

    connect(renderButton, SIGNAL(clicked()), this, SLOT(renderScene()));
}
Exemplo n.º 13
0
void Game::renderScreen()
{
  m_currentCam->setAsCamera();

  renderScene(false);

  PlaneObject *plane = objects->getPlaneObject();
  if(plane != NULL)
  {
    //render plane reticles    
    plane->renderReticle(15.0f, 1.3f);
    plane->renderReticle(8.0f, 1.0f);
    
    if (plane->isPlaneAlive() == false)
    {
      int textY = gRenderer.getScreenY()/2;
      IRectangle rect = IRectangle(0,textY,gRenderer.getScreenX()-1, textY + 30);
      gRenderer.drawText("Press \"Space Bar\" to Respawn",&rect, eTextAlignModeCenter, false);
    }
  }

  gConsole.render();
  if (GameBase::m_renderInfo)
    GameBase::renderInfo();  
}
//extern void update();
void update()
{
	// add any update code here...

	// always re-render the scene..
	renderScene();
}
Exemplo n.º 15
0
void onDraw()
{
  /*setViewer O(1)*/
  setMatrixMode(PROJECTION);
  initMatrix();
  setViewer(vertex(eyex, eyey, eyez), vertex(lookx, looky, lookz), vertex(upx, upy, upz));
  setFrustum(10, 10*MAX_H/MAX_W, 4, 25);

  /*createPolygons O(1)*/
  initScene();
  setMatrixMode(MODELVIEW); 
  initMatrix();
  blockWithHole(-5.0,0.0,0.0);
  blockColoured(barx, bary, 0.0);

 
  /*calcData*/
  /*
    For each polygon,
      Go to next triangle if current polygon doesn't face viewer O(1)
      Calculate pixel values of vertices of the triangle O(1)
      clip triangle  //unless you model your scene such that no part ever goes outside the viewport (commentception) O(1)
      For each triangle, O(m*n)
        Add x,y,z position of scan conversion pixels to temp per-polygon table (indexed on y position with min and max x values)
        Also store a min and max x for y=0, y=MAX_Y-1. Add the x,y values for the points in between to the temp table
        Copy temp table to data table with the points between min and max x values filled (in case of conlict, min z value only) O(m*n)
  */

  /*drawPixels*/
  if(q4) innerclipTriangles();
  renderScene();
  glDrawPixels(MAX_W, MAX_H, GL_RGBA, GL_BYTE, data);
  glFlush();
}
Exemplo n.º 16
0
void main()
{
	glfwInit();

	// Create a window
	window = glfwCreateWindow(800, 800, "Jarvis March", nullptr, nullptr);
	glfwMakeContextCurrent(window);
	glfwSwapInterval(0);

	// Initializes most things needed before the main loop
	init();

	//Generate the point mesh
	Vertex pointVertex;
	pointVertex.x = pointVertex.y = pointVertex.z = pointVertex.r = 0.0f;
	pointVertex.g = pointVertex.b = pointVertex.a = 1.0f;

	//rope creation
	point = new struct Mesh(1, &pointVertex, GL_POINTS);

	//Scale the rope
	point->scale = glm::scale(point->scale, glm::vec3(1.0f));

	//Generate 25 rigidbodies
	for(int i = 0; i < 25; i++)
	{
		float x = (static_cast <float> (rand()) / static_cast <float> (RAND_MAX)) - 0.5f;
		float y = (static_cast <float> (rand()) / static_cast <float> (RAND_MAX)) - 0.5f;

		bodies.push_back(RigidBody(glm::vec3(0.0f), glm::vec3(x, y, 0.0f)));
	}

	// Enter the main loop.
	while (!glfwWindowShouldClose(window))
	{
		//Check time will update the programs clock and determine if & how many times the physics must be updated
		checkTime();

		// Call the render function.
		renderScene();

		// Swaps the back buffer to the front buffer
		// Remember, you're rendering to the back buffer, then once rendering is complete, you're moving the back buffer to the front so it can be displayed.
		glfwSwapBuffers(window);

		// Checks to see if any events are pending and then processes them.
		glfwPollEvents();
	}

	// After the program is over, cleanup your data!
	glDeleteShader(vertex_shader);
	glDeleteShader(fragment_shader);
	glDeleteProgram(program);
	// Note: If at any point you stop using a "program" or shaders, you should free the data up then and there.

	delete point;

	// Frees up GLFW memory
	glfwTerminate();
}
Exemplo n.º 17
0
// The main method.
int main(int argc, char** argv) {
  const char* fileName = "Img";
  // Print usage info.
  if (argc > 4) {
    printf("Usage: %s <optional: output> <optional: chunks chunknr> "
           "<optional: random seed>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  // Initialize the rand function.
  unsigned int seed = static_cast<unsigned int>(time(NULL));
  if (argc > 1) {
    fileName = argv[1];
  }
  size_t chunks = 1;
  size_t chunkNr = 0;
  if (argc > 3) {
    chunks = atol(argv[2]);
    chunkNr = atol(argv[3]);
  }
  if (argc == 5) {
    seed = static_cast<unsigned int>(atoi(argv[4]));
  }
  printf("Random seed used: %u\n\n", seed);
  srand(seed);

  // Render our test scene.
  renderScene(fileName, chunks, chunkNr);
}
Exemplo n.º 18
0
void View::mainLoop() {
	short continuer = 1;
	SDL_Event event;
	SDL_EnableKeyRepeat(40,40);
	SDL_WM_GrabInput(SDL_GRAB_ON);
	SDL_ShowCursor(SDL_DISABLE);
	while ( SDL_PollEvent(&event) ); // empty queue.

	int lastTime = SDL_GetTicks() - 30;
	int currentTime = 0;

	while (continuer) {
		lastTime = currentTime;
		currentTime = SDL_GetTicks();
		while ( SDL_PollEvent(&event) ) {
			switch(event.type) {
			case SDL_QUIT:
				continuer = 0;
				break;
			case SDL_KEYDOWN:
			case SDL_KEYUP:
				camera.keyboard(event.key);
				break;
			case SDL_MOUSEMOTION:
				camera.mouseMotion(event.motion);
				break;
			default:
				break;
			}
		}
		renderScene(lastTime,currentTime);
	}

	SDL_Quit();
}
Exemplo n.º 19
0
void updateGL() {
    //Done TODO: also clear the stencil buffer before rendering again //
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

    // set viewport dimensions //
    glViewport(0, 0, windowWidth, windowHeight);

    // get projection mat from camera controller //
    glm_ProjectionMatrix.top() = camera.getProjectionMat();
    // upload projection matrix //
    glUniformMatrix4fv(uniformLocations["projection"], 1, false, glm::value_ptr(glm_ProjectionMatrix.top()));

    // init scene graph by cloning the top entry, which can now be manipulated //
    // get modelview mat from camera controller //
    glm_ModelViewMatrix.top() = camera.getModelViewMat();

    // #INFO# render scene //
    renderScene();

    // #INFO# render shadow volume //
    renderShadow();

    // swap renderbuffers for smooth rendering //
    glutSwapBuffers();
}
Exemplo n.º 20
0
void render(void) {
	glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

	renderScene();

	glutSwapBuffers();
}
Exemplo n.º 21
0
void GlutViewer::UpdateGeometry(PointCloudStorage* cloud)
{
	if (cloud != NULL)
		this->cloud = cloud;

	renderScene();
}
Exemplo n.º 22
0
void handleSelection(int x, int y)
{
	glInitNames();
	GLuint hitBuffer[64] = {0};
	glSelectBuffer(64, hitBuffer);
	glRenderMode(GL_SELECT);
	GLint vp[4];
	glGetIntegerv(GL_VIEWPORT,vp);
 	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	gluPickMatrix(x,currentRes[1]-y,5.0,5.0,vp);
	gluPerspective(45.0,RESOLUTION_X/RESOLUTION_Y, 0.5, 50.0);
	glScalef((float)RESOLUTION_X/currentRes[0], (float)RESOLUTION_Y/currentRes[1], 1.0);
  
	glMatrixMode(GL_MODELVIEW);
	renderScene();
	glMatrixMode(GL_PROJECTION);
  
  	glPopMatrix();
  	glFlush();
  	GLint hitCount = glRenderMode(GL_RENDER);
  	listSelected(hitCount, hitBuffer);
	glMatrixMode(GL_MODELVIEW);
}
Exemplo n.º 23
0
void GLWidget::paintGL()
{
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    if(withshadow){

    glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT);
    glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
        glClear(GL_DEPTH_BUFFER_BIT);
        renderSceneShadow();
    glBindFramebuffer(GL_FRAMEBUFFER, 0);

    // 2. Render scene as normal
    glViewport(0, 0, winWidth, winHeight);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glActiveTexture(GL_TEXTURE1);
    glBindTexture(GL_TEXTURE_2D, depthMap);
    renderSceneWithShadow();

    }else{
        renderScene();
    }





}
Exemplo n.º 24
0
void display() {
    glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    // crtanje scene:
    renderScene();
    glutSwapBuffers();
}
 void draw() {
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   gl::MatrixStack & mv = gl::Stacks::modelview();
   gl::MatrixStack & pr = gl::Stacks::projection();
   gl::Stacks::with_push(mv, pr, [&]{
     renderScene();
   });
 }
Exemplo n.º 26
0
void SceneRenderToTex::render()
{
    glBindFramebuffer(GL_FRAMEBUFFER, fboHandle);
    renderToTexture();

    glBindFramebuffer(GL_FRAMEBUFFER, 0);
    renderScene();
}
Exemplo n.º 27
0
bool ClientEngine::onUpdate(double timeDelta)
{
	m_Client.service();
	if(!renderScene())
		return false;
	m_ObjectManager.update();
	return true;
}
Exemplo n.º 28
0
Arquivo: Stage.cpp Projeto: jejatu/3d
void Stage::renderDirectionalLightShadowMap(Light* light, Camera* shadowMapCamera) {
	if (light->shadow != Shadows::None) {
		DirectionalLight* dirLight = (DirectionalLight*) light;
		//directional light only needs one shadow map texture
		//light camera is supposed to be setup so that ortho frustum contains all that the main camera sees
		float quantizeFactor = 0;
		std::vector<glm::vec3> frustumCorners;
		if (dirLight->getShadowMethod() == DirectionalShadowMethods::Basic) {
			frustumCorners = m_camera->getFrustumCorners();
			quantizeFactor = m_camera->getFar() * 0.3f;
		} else if (dirLight->getShadowMethod() == DirectionalShadowMethods::Near) {
			Camera newCamera;
			newCamera.initPerspective(m_camera->getFov(),
									  m_camera->getAspectRatio(),
									  m_camera->getNear(), 
									  m_camera->getFar() * dirLight->getShadowMethodValue());
			newCamera.setTransform(m_camera->getTransform());
			frustumCorners = newCamera.getFrustumCorners();
			quantizeFactor = m_camera->getFar() * dirLight->getShadowMethodValue() * 0.3f;
		}
		glm::mat4 lightView = light->getTransform();
		glm::mat4 invLightView = glm::inverse(lightView);
							
		for (int j = 0; j < 8; ++j) {
			frustumCorners[j] = glm::vec3(lightView * glm::vec4(frustumCorners[j], 1));
			frustumCorners[j].x = glm::ceil(frustumCorners[j].x / quantizeFactor) * quantizeFactor;
			frustumCorners[j].y = glm::ceil(frustumCorners[j].y / quantizeFactor) * quantizeFactor;
			frustumCorners[j].z = glm::ceil(frustumCorners[j].z / quantizeFactor) * quantizeFactor;
		}

		BoundingBox lightBox(frustumCorners);
		lightBox.max.z += 100;
		lightBox.min.z -= 100;

		glm::vec3 boxSize = lightBox.max - lightBox.min;
		glm::vec3 halfBoxSize = boxSize * 0.5f;

		glm::vec3 lightPosition = lightBox.min + halfBoxSize;
		lightPosition.z = lightBox.min.z;

		lightPosition = glm::vec3(invLightView * glm::vec4(lightPosition, 1));

		shadowMapCamera->lookAt(lightPosition,
								lightPosition + light->getForward(),
								light->getUp());
		shadowMapCamera->setProjection(glm::ortho(-boxSize.x, boxSize.x, -boxSize.y, boxSize.y, -boxSize.z, boxSize.z));

		ShaderProgram* depthShader = &m_allShaders.esmDepth;
		if (light->shadow == Shadows::VSM) {
			depthShader = &m_allShaders.vsmDepth;
		}

		m_shadowMap.bind();
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		renderScene(depthShader, shadowMapCamera, light);
		m_shadowMap.unbind();
	}
}
Exemplo n.º 29
0
void main()
{
    glfwInit();

    // Creates a window given (width, height, title, monitorPtr, windowPtr).
    // Don't worry about the last two, as they have to do with controlling which monitor to display on and having a reference to other windows. Leaving them as nullptr is fine.
    window = glfwCreateWindow(800, 800, "3D Sphere SAT (MTV and decoupling)", nullptr, nullptr);

    std::cout << "\n This program demonstrates the implementation SAT between two Spheres\n\n\n\n\n\n\n\n\n\n";
    std::cout << "\n Press \" Space \" to toggle between the objects.";
    std::cout << "\n Use \"a,s,d\" to rotate the selected object.";
    std::cout << "\n Use \"i,j,k,l\" to move in XY plane";
    std::cout << "\n Use \"u and o\" to move in Z axis";

    // Makes the OpenGL context current for the created window.
    glfwMakeContextCurrent(window);

    // Sets the number of screen updates to wait before swapping the buffers.
    // Setting this to zero will disable VSync, which allows us to actually get a read on our FPS. Otherwise we'd be consistently getting 60FPS or lower,
    // since it would match our FPS to the screen refresh rate.
    // Set to 1 to enable VSync.
    glfwSwapInterval(0);

    // Initializes most things needed before the main loop
    init();

    // Sends the funtion as a funtion pointer along with the window to which it should be applied to.
    glfwSetKeyCallback(window, key_callback);

    setup();

    // Enter the main loop.
    while (!glfwWindowShouldClose(window))
    {
        // Call to update() which will update the gameobjects.
        update();

        // Call the render function.
        renderScene();

        // Swaps the back buffer to the front buffer
        // Remember, you're rendering to the back buffer, then once rendering is complete, you're moving the back buffer to the front so it can be displayed.
        glfwSwapBuffers(window);

        // Checks to see if any events are pending and then processes them.
        glfwPollEvents();
    }

    // After the program is over, cleanup your data!
    glDeleteShader(vertex_shader);
    glDeleteShader(fragment_shader);
    glDeleteProgram(program);
    // Note: If at any point you stop using a "program" or shaders, you should free the data up then and there.


    // Frees up GLFW memory
    glfwTerminate();
}
Exemplo n.º 30
0
// Rotina Principal do programa
int main(int argc, char **argv) {

  double start, finish;
  int i;

  if(argc != 2){
    printf("Usage: %s <number of particles>\n",argv[0]);
    return 0;
  }

  // Recebe o número de partículas que devem ser processadas
  // e posteriormente renderizadas
  nParticulas = atoi(argv[1]);

  // Define a quantidade de partículas que não estão no chão (inicialmente nenhuma delas está)
  nParticulasAux = nParticulas;

  // Define posição inicial das particulas
  iniciarParticula();

  // Funções necessárias para inicializar o OpenGL
  // e criar a janela que ficará renderizando
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
  glutInitWindowPosition(100,100);
  glutInitWindowSize(640,640);
  glutCreateWindow("Trabalho Final - Computação Paralela");
  glEnable(GL_DEPTH_TEST);

  // Inicializa a contagem do tempo
  GET_TIME(start);

  // Registrando CallBacks
  glutDisplayFunc(renderScene);
  glutReshapeFunc(changeSize);
  glutIdleFunc(renderScene);

  // Função que mantém o loop do evento de renderização
  // funcionado
  // Foi escolhido a função glutMainLoopEvent ao invés de glutMainLoop
  // pelo simples fato de que a segunda não pára até o programa finalizar
  // e a que escolhemos funciona como apenas uma iteração dessa função
  while(!Flag)
  {
    glutMainLoopEvent();
    renderScene();
  }

  // Finaliza o timer
  GET_TIME(finish);

  // Printa o tempo
  printf("Tempo gasto: %f\n", (finish - start));

  free(vetor2);

  return 1;
}