Beispiel #1
0
// OrthographicCamera Definitions
OrthoCamera::OrthoCamera(const Transform &world2cam,
		const float Screen[4], float hither, float yon,
		float sopen, float sclose, float lensr,
		float focald, Film *f)
	: ProjectiveCamera(world2cam, Orthographic(hither, yon),
		 Screen, hither, yon, sopen, sclose,
		 lensr, focald, f) {
}
Beispiel #2
0
// OrthographicCamera Definitions
OrthoCamera::OrthoCamera(const AnimatedTransform &cam2world,
                         const float screenWindow[4], float sopen, float sclose,
                         float lensr, float focald, Film *f)
    : ProjectiveCamera(cam2world, Orthographic(0., 1.), screenWindow,
                       sopen, sclose, lensr, focald, f) {
    // Compute differential changes in origin for ortho camera rays
    dxCamera = RasterToCamera(Vector(1, 0, 0));
    dyCamera = RasterToCamera(Vector(0, 1, 0));
}
Beispiel #3
0
void Backbuffer::Resize(uint32_t width, uint32_t height)
{
  DeleteTexture();
  CreateTexture(width, height);

  m_Projection = Orthographic(-1.0f, 2 * width / (float)m_TextureSize - 1,
    -1.0f, 2 * height / (float)m_TextureSize - 1,
    1.0f, -1.0f);

  m_Image.resize(height, width);
}
Beispiel #4
0
static void 
RenderImGuiDrawList(ImDrawData *data) {
	ImGuiIO& io = ImGui::GetIO();
	GameMemory *memory = (GameMemory*)io.UserData;
	RenderState *rs = &memory->renderState;
	SystemInfo *system = &memory->systemInfo;
	memory->renderState.imgui_draw_data = data;

	glDisable(GL_CULL_FACE);
	glDisable(GL_DEPTH_TEST);
	glEnable(GL_SCISSOR_TEST);
	glEnable(GL_BLEND);
	glBlendEquation(GL_FUNC_ADD);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	glViewport(0, 0, system->screenWidth, system->screenHeight);
	glUseProgram(GetShaderProgram(ShaderID_Sprite, &memory->assetManifest));
	M4 screenProjection = Orthographic(0.0f, system->screenWidth, 
    0.0f, system->screenHeight, -1.0f, 100.0f, -1.0f);
	glUniformMatrix4fv(2, 1, GL_FALSE, &screenProjection[0][0]);
  glBindVertexArray(rs->imguiRenderGroup.vao);
  glActiveTexture(GL_TEXTURE0);

  ImDrawData *draw_data = rs->imgui_draw_data;
  for (int i = 0; i < rs->imgui_draw_data->CmdListsCount; i++) {
    const ImDrawList *draw_list = draw_data->CmdLists[i];
    const ImDrawIdx *index_buffer_offset = 0;
    glBindBuffer(GL_ARRAY_BUFFER, rs->imguiRenderGroup.vbo);
    glBufferData(GL_ARRAY_BUFFER, draw_list->VtxBuffer.size() * sizeof(ImDrawVert),
      &draw_list->VtxBuffer.front(), GL_DYNAMIC_DRAW);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, rs->imguiRenderGroup.ebo);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, draw_list->IdxBuffer.size() * sizeof(ImDrawIdx),
      &draw_list->IdxBuffer.Data[0], GL_DYNAMIC_DRAW);

    for (const ImDrawCmd* cmd = draw_list->CmdBuffer.begin();  cmd != draw_list->CmdBuffer.end(); cmd++) {
      glBindTexture(GL_TEXTURE_2D, (GLuint)(uintptr_t)cmd->TextureId);
      glDrawElements(GL_TRIANGLES, cmd->ElemCount, GL_UNSIGNED_SHORT, index_buffer_offset);
      index_buffer_offset += cmd->ElemCount;
    }

    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
  }

	glDisable(GL_SCISSOR_TEST);
	glUseProgram(0);
}
Beispiel #5
0
//-------------------------------------------------------------------------------
// @ Game::Render()
//-------------------------------------------------------------------------------
// Render stuff
//-------------------------------------------------------------------------------
void 
Game::Render()                                  
{       
    // set perspective matrix
    float aspect = (float)IvRenderer::mRenderer->GetWidth()/(float)IvRenderer::mRenderer->GetHeight();
    if ( mUseOrthographic )
    {
        Orthographic( -aspect*3.0f+mXCenter, aspect*3.0f+mXCenter,
                   -3.0f+mYCenter, 3.0f+mYCenter,
                    IvRenderer::mRenderer->GetNearPlane(), 
                    IvRenderer::mRenderer->GetFarPlane() );
    }
    else
    {
        Frustum( -aspect*3.0f+mXCenter, aspect*3.0f+mXCenter,
                   -3.0f+mYCenter, 3.0f+mYCenter,
                    IvRenderer::mRenderer->GetNearPlane(), 
                    IvRenderer::mRenderer->GetFarPlane() );
    }

    // set viewer
    ::IvSetDefaultViewer( 6.0f, 0.0f, 5.f );

    // draw axes
    ::IvDrawAxes();

    // draw floor
    ::IvDrawFloor();

    // draw some objects
    IvMatrix44 worldTransform;
    worldTransform.Translation( IvVector3( 0.1f, 0.0f, 1.0f ) );
    ::IvSetWorldMatrix( worldTransform );
    ::IvDrawCube();

    worldTransform.Translation( IvVector3( 0.1f, 3.0f, 0.0f ) );
    ::IvSetWorldMatrix( worldTransform );
    ::IvDrawTeapot();

    worldTransform.Translation( IvVector3( 0.1f, -2.5f, 1.0f ) );
    ::IvSetWorldMatrix( worldTransform );
    ::IvDrawSphere( 1.0f );

}
Beispiel #6
0
TEST(RayTracerTest, TurbineMeshTest) {
  SceneLoader& loader = SceneLoader::GetInstance();
  std::string path = "../assets/blade.ply";
  std::string status = "";
  Scene scene;
  std::cout << "loading" << std::endl;
  bool success = loader.LoadScene(path, scene, status);
  EXPECT_TRUE(success);
  EXPECT_EQ("OK", status);
  std::cout << "done loading" << std::endl;
  int image_width = 1024;
  int image_height = 1024;
  glm::vec3 eye_pos = glm::vec3(-274.564f, -282.243f, 950.0f);
  glm::vec3 at_pos = glm::vec3(-274.564f, -282.243f, 254.327f);
  glm::vec3 up_dir = glm::vec3(0.0f, 1.0f, 0.0f);
  std::cout << "set camera" << std::endl;
  glm::mat4x4 look_at = LookAt(eye_pos, at_pos, up_dir);
  Camera camera(image_width, image_height, Orthographic(0.0f, 1.0f), look_at);
  std::cout << "camera set" << std::endl;

  Light point_light;
  glm::vec3 point_light_color = glm::vec3(0.4f, 0.4f, 0.4f);
  point_light.ka = point_light_color;
  point_light.kd = point_light_color;
  point_light.ks = point_light_color;
  point_light.ray = Ray(glm::vec3(0.0, -400.0, 400.0f), glm::vec3(0.0f));
  point_light.type = Light::kPoint;
  point_light.attenuation_coefficients = glm::vec3(0.25f, 0.003372407f,
      0.000045492f);

  Light directional_light;
  glm::vec3 directional_light_color = glm::vec3(0.4f, 0.4f, 0.4f);
  directional_light.ka = directional_light_color;
  directional_light.kd = directional_light_color;
  directional_light.ks = directional_light_color;
  directional_light.ray = Ray(glm::vec3(0.0f), glm::vec3(0.0f, -1.0f, -1.0f));
  directional_light.type = Light::kDirectional;

  scene.AddLight(point_light);
  scene.AddLight(directional_light);

  Trimesh* trimesh = static_cast<Trimesh*>(scene.scene_objects()[0]);
  OctreeType octree;
  std::cout << "Building octree" << std::endl;
  octree.Build(trimesh->faces());
  //octree.set_trace(true);
  //octree.Print(std::cout);
  std::cout << "Octree built.\n";
  std::cout << "bounds = " << octree.GetBounds() << " center = "
      << octree.GetBounds().GetCenter() << std::endl;
  trimesh->set_accelerator(&octree);
  Image image;
  image.Resize(image_width, image_height);
  RayTracer ray_tracer(&scene, &camera);
  ray_tracer.set_display_progress(!use_timing);
  ray_tracer.set_display_stats(!use_timing);
  ray_tracer.set_background_color(glm::vec3(0.05f, 0.05f, 0.05f));

  timeval t_start, t_finish;
  if (use_timing)
    gettimeofday(&t_start, NULL);
  std::cout << "Rendering..." << std::endl;
  ray_tracer.Render(image);
  if (use_timing) {
    gettimeofday(&t_finish, NULL);
    float sec = t_finish.tv_sec - t_start.tv_sec + t_finish.tv_usec / 1000000.0f
        - t_start.tv_usec / 1000000.0f;
    std::cout << "Render time:" << sec << std::endl;
  } else
    std::cout << "Done." << std::endl;

  ImageStorage& storage = ImageStorage::GetInstance();
  success = storage.WriteImage("blade_octree.jpg", image, status);
  EXPECT_TRUE(success);
  EXPECT_EQ("OK", status);
}
Beispiel #7
0
int main()
{
	//setup to log some GLFW stuff

	char message[256];
	sprintf (message, "starting GLFW %s", glfwGetVersionString ());
	assert (gl_log (message, __FILE__, __LINE__));
	glfwSetErrorCallback (glfw_error_callback);

	//open an OS window using GLFW
	if(!glfwInit())
	{
		fprintf (stderr,"ERROR: could not start GLFW3\n");
		return 1;
	}

	// uncomment these lines if on Apple OS X
	/*	glfwWindowHint (GLFW_CONTEXT_VERSION_MAJOR, 3);
	glfwWindowHint (GLFW_CONTEXT_VERSION_MINOR, 2);
	glfwWindowHint (GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
	glfwWindowHint (GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
	*/	
	//Anti-Aliasing
	glfwWindowHint (GLFW_SAMPLES, 4);

	//get the primary monitor
	GLFWmonitor* mon = glfwGetPrimaryMonitor ();
	//this lets us the the video mode for the monitor we pass
	const GLFWvidmode* vmode = glfwGetVideoMode (mon);
	GLFWwindow* window = glfwCreateWindow (
		vmode->width, vmode->height, "Extended GL Init",NULL/* mon*/, NULL
		);
	glfwSetWindowSize(window, g_gl_width, g_gl_height);

	if (!window) {
		fprintf (stderr, "ERROR: could not open window with GLFW3\n");
		glfwTerminate();
		return 1;
	}
	//not sure if this works
	//log_gl_params ();

	glfwMakeContextCurrent(window);

	//start GLEW extension handler
	glewExperimental = GL_TRUE;
	glewInit();

	// get version info
	const GLubyte* renderer = glGetString (GL_RENDERER); // get renderer string
	const GLubyte* version = glGetString (GL_VERSION); // version as a string
	printf ("Renderer: %s\n", renderer);
	printf ("OpenGL version supported %s\n", version);

	// tell GL to only draw onto a pixel if the shape is closer to the viewer
	glEnable (GL_DEPTH_TEST); // enable depth-testing
	glDepthFunc (GL_LESS); // depth-testing interprets a smaller value as "closer"

	float speed = 1.0f; // move at 1 unit per second
	float last_position = 0.0f;

	//Quad * tester = new Quad();

	Sprite * richard = new Sprite("./resources/simmons.png", 384, 324, Vector4(1,1,1,1), window); 


	//int matrix_location = glGetUniformLocation (shaderProgram, "matrix");
	//glUniform1i(glGetUniformLocation(shaderProgram, "Texture"), 0);

	Ortho = new Matrix4();
	Orthographic(0, g_gl_width, g_gl_height, 0, 0, -1, Ortho);

	while (!glfwWindowShouldClose (window)) {

		/* add a timer for doing animation
  static double previous_seconds = glfwGetTime ();
  double current_seconds = glfwGetTime ();
  double elapsed_seconds = current_seconds - previous_seconds;
  previous_seconds = current_seconds;
   // reverse direction when going to far left or right
  if (fabs(last_position) > 1.0f) {
    speed = -speed;
  }
  */

		glEnable (GL_CULL_FACE); // cull face
		glCullFace (GL_BACK); // cull back face
		glFrontFace (GL_CW); // GL_CCW for counter clock-wise

		// wipe the drawing surface clear
		glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		//resize window
		glViewport (0, 0, g_gl_width, g_gl_height);

	
		
		  // update the matrix
//  matrix[12] = elapsed_seconds * speed + last_position;
//  last_position = matrix[12];
		//set the shader for this VAO
//		glUseProgram (shaderProgram);
		//Here is where we attach the marix
//		glUniformMatrix4fv (matrix_location, 1, GL_FALSE, matrix);
		//bind the VAO to be drawn
//		glBindVertexArray (VAO);
		// draw points 0-3 from the currently bound VAO with current in-use shader
//		glDrawArrays (GL_TRIANGLES, 0, 3);

		richard->Input();
		richard->Draw();

		// update other events like input handling 
		glfwPollEvents ();
		// put the stuff we've been drawing onto the display
		glfwSwapBuffers (window);


		//When do i exit?
		if (GLFW_PRESS == glfwGetKey (window, GLFW_KEY_ESCAPE)) {
			glfwSetWindowShouldClose (window, 1);
		}
	}

	// close GL context and any other GLFW resources
	glfwTerminate();
	return 0;

}
int main() {
	char message[256];
	sprintf(message, "staring glfw %s", glfwGetVersionString());
	assert(GL_log(message, __FILE__, __LINE__));
	glfwSetErrorCallback(glfw_error_callback);

	//open and OS window using glfw
	if (!glfwInit()) {
		fprintf (stderr,"ERROR: could not start GLFW3\n");
		return 1;
	}

	glfwWindowHint(GLFW_SAMPLES, 4);

	//get primary monitor
	GLFWmonitor* mon = glfwGetPrimaryMonitor();

	//this lets us use the video mode for the monitor we pass
	const GLFWvidmode* vmode = glfwGetVideoMode(mon);

	GLFWwindow* window = glfwCreateWindow(vmode->width, vmode->height, "Extended GL Init", NULL/*mon*/, NULL);

	glfwSetWindowSize(window, g_gl_width, g_gl_height);

	if (!window) {
		fprintf (stderr,"ERROR: could not open window GLFW3\n");
		glfwTerminate();
		return 1;
	}

	glfwMakeContextCurrent(window);

	//start glew extention handler
	glewExperimental = GL_TRUE;
	glewInit();

	//get version info
	const GLubyte * renderer = glGetString (GL_RENDERER); //get renderer string
	const GLubyte * version = glGetString (GL_VERSION); //get version as a string
	printf ("Renerer: %s\n", renderer);
	printf ("OpenGL version supported %s\n", version);

	//tell GL to only draw onto a pixel if the shape is closer to the viewer
	glEnable (GL_DEPTH_TEST); //enable depth testing
	glDepthFunc (GL_LESS);

	/* other stuff goes here */

	/*float points[] = {
		0.0f, 0.5, 0.0f,
		0.5f, -0.5f, 0.0f,
		-0.5f, -0.5f, 0.0f
	};

	GLuint VBO = 0;
	glGenBuffers(1, &VBO);
	glBindBuffer(GL_ARRAY_BUFFER, VBO);
	glBufferData(GL_ARRAY_BUFFER, 9 * sizeof (float), points, GL_STATIC_DRAW);
	GLuint VAO = 0;
	glGenVertexArrays(1, &VAO);
	glBindVertexArray(VAO);
	glEnableVertexAttribArray(0);
	glBindBuffer(GL_ARRAY_BUFFER, VBO);
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (GLubyte*)NULL);

	const char* vertex_shader =
		"#version 330\n"
		"in vec3 pos;\n"
		"void main() {"
		"gl_Position = vec4(pos, 1.0);\n"
		"}";
	const char* fragment_shader =
		"#version 330\n"
		"out vec4 frag_colour;\n"
		"void main() {"
		"frag_colour = vec4(0.5, 0.0, 0.5, 1.0);\n"
		"}";

	//create a shader
	GLuint vs = glCreateShader(GL_VERTEX_SHADER);
	//put the actual cha* int the shader
	glShaderSource(vs, 1, &vertex_shader, NULL);
	//compile the shader
	glCompileShader(vs);
	PrintShaderInfoLog(vs);
	GLuint fs = glCreateShader(GL_FRAGMENT_SHADER);
	glShaderSource(fs, 1, &fragment_shader, NULL);
	glCompileShader(fs);
	PrintShaderInfoLog(fs);
	//create the container that holds the shaders
	GLuint shaderProgram = glCreateProgram();
	//attach the shaders
	glAttachShader(shaderProgram, fs);
	glAttachShader(shaderProgram, vs);
	//this inks the shaders together, its kinda like a compile
	glLinkProgram(shaderProgram);
	PrintProgramInfoLog(shaderProgram);



	//new object
	float Spoints[] = {
		-0.25f, -0.5f, 0.0f,
		-0.25f, -0.75f, 0.0f,
		0.25f, -0.5f, 0.0f,
		0.25f, -0.75f, 0.0f
	};

	GLuint VBO2 = 0;
	glGenBuffers(1, &VBO2);
	glBindBuffer(GL_ARRAY_BUFFER, VBO2);
	glBufferData(GL_ARRAY_BUFFER, 12 * sizeof (float), Spoints, GL_STATIC_DRAW);
	GLuint VAO2 = 0;
	glGenVertexArrays(1, &VAO2);
	glBindVertexArray(VAO2);
	glEnableVertexAttribArray(0);
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (GLubyte*)NULL);

	const char* vertex_shader2 =
		"#version 330\n"
		"in vec3 vp;\n"
		"void main() {"
		"gl_position = vec4(vp, 2.0);\n"
		"}";
	const char* fragment_shader2 =
		"#version 330\n"
		"out vec4 frag_colour;\n"
		"void main() {"
		"frag_colour = vec4(0.5, 0.0, 0.0, 1.0);\n"
		"}";

	//create a shader
	GLuint vs2 = glCreateShader(GL_VERTEX_SHADER);
	//put the actual char* in the shader
	glShaderSource(vs2, 1, &vertex_shader2, NULL);
	//compile the shader
	glCompileShader(vs2);
	PrintShaderInfoLog(vs2);
	GLuint fs2 = glCreateShader(GL_FRAGMENT_SHADER);
	glShaderSource(fs2, 1, &fragment_shader2, NULL);
	glCompileShader(fs2);
	PrintShaderInfoLog(fs2);
	//create the container that holds the shaders
	GLuint secondProgram = glCreateProgram();
	//attach the shaders
	glAttachShader(secondProgram, fs2);
	glAttachShader(secondProgram, vs2);
	//this inks the shaders together, its kinda like a compile
	glLinkProgram(secondProgram);
	PrintProgramInfoLog(secondProgram);
	*/

	Ortho = new Matrix4();
	Orthographic(0, g_gl_width, g_gl_height, 0, 0, -1, Ortho);

	//Quad * tester1 = new Quad();

	AnimatedSprite * tester = new AnimatedSprite("../resources/MegamanXSheet.xml", window);

	tester->SetAnimation("teleport", ONCE);
	

	while (!glfwWindowShouldClose(window)) {
		//_update_fps_counter(window);
		glEnable(GL_ALPHA_TEST);
		glAlphaFunc(GL_GREATER, 0.5);
		glEnable(GL_ALPHA);
		glEnable(GL_CULL_FACE);
		glCullFace(GL_BACK);
		glFrontFace(GL_CW);

		//wipe the drawing surface
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		//resize window
		glViewport (0, 0, g_gl_width, g_gl_height);
		
		tester->Update();
		//tester->Draw();
		//tester->Input();
		
		//update other events like input handling
		glfwPollEvents();
		//put the stuff we've been drawing into the display
		glfwSwapBuffers(window);
		
		resetDeltaTime();
		if (GLFW_PRESS == glfwGetKey(window, GLFW_KEY_ESCAPE)) {
			glfwSetWindowShouldClose(window, 1);
		}
	}

	//close GL context and any other GLFW resources
	//delete Ortho;
	//delete tester;
	glfwTerminate();
	return 0;
}
Beispiel #9
0
void	CRenderer::Orthographic()
{
	Orthographic( m_spDisplay->Width(), m_spDisplay->Height() );
}
Beispiel #10
0
void Camera::SetOrthographic(float left, float right, float bottom, float top, float n, float f){
	m_matProj = Orthographic(left, right, bottom, top, n, f);
}