Ejemplo n.º 1
0
int main(int argc, char* argv[]) {

	glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
    glutInitWindowSize(INITIAL_WIDTH, INITIAL_HEIGHT);
    glutCreateWindow("CG Final Project");
#ifndef __APPLE__
    glewInit();
#endif
    if (!GLEW_VERSION_2_0) {
        fprintf(stderr, "OpenGL 2.0 not available\n");
    }
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);
    glClearColor(.9f, 1.0f, 1.0f, 1.0f);
	//glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); //used for wire frames

	Shader myShader("v.glsl", "f.glsl");
	Window myWindow(&myShader, argc, argv);

	float translation[3] = { -1, 2.5, -1.5}; 
	Flag *flag = new Flag("american.jpg");
	Flagpole *flagpole = new Flagpole("InteriorWoodFlooringMedium_01.jpg");
	flagpole->rotateY(90);
	flag->rotateZ(-90);
	flag->rotateX(-10);
	flagpole->rotateZ(90);
	flag->rotateY(20);
	flagpole->rotateY(20);
	flag->translate(translation);
	flagpole->translate(translation);
	myWindow.addMesh(flag);
	myWindow.addMesh(flagpole);
	
	translation[0] = 1.6; translation[1] = -0.2; translation[2] = -1;
	float scale[3] = {1.5,1.5,1.5};
	objMesh *couch = new objMesh("leather.jpg", "Couch.obj", true, true, 10, brown);
	objMesh *couch2 = new objMesh("leather.jpg", "Couch2.obj", true, true, 100, brown);
	couch->scale(scale); 	couch2->scale(scale);  
	couch->translate(translation); 	
	translation[0] = 1.1; translation[1] = 0; translation[2] = -1.3; 
	couch2->translate(translation);
	myWindow.addMesh(couch); myWindow.addMesh(couch2);

	translation[0] = 0; translation[1] = -1; translation[2] = 0; 
	objMesh *cowhide = new objMesh("fur.jpg", "cowhide.obj", true, true, 100, black);
	cowhide->translate(translation);
	myWindow.addMesh( cowhide );
	
	translation[0] = 2; translation[1] = 0.3; translation[2] = -1; 
	objMesh *lamp = new objMesh("metallic.jpg", "Light.obj", true, true, 1, grey);
	lamp->rotateY(-60);
	lamp->translate(translation);
	myWindow.addMesh(lamp);

	translation[0] = -2; translation[1] = -1; translation[2] = -1; 
	objMesh *table = new objMesh("wood.jpg", "Coffee.obj", true, true, 100, brown);
	table->translate(translation);
	myWindow.addMesh(table);

	translation[0] = 0; translation[1] = -1; translation[2] = .3; 
	objMesh *books = new objMesh("red.jpg", "Books.obj", true, true, 100, red);
	books->translate(translation);
	myWindow.addMesh(books);

	translation[0] = -2; translation[1] = -0.4; translation[2] = -1; 
	objMesh *twig = new objMesh("", "Twig.obj", true, true, 10, dRed);
	twig->translate(translation);
	myWindow.addMesh(twig);

	translation[0] = -2; translation[1] = -0.4; translation[2] = -0.7; 
	objMesh *glass = new objMesh("glass.jpg", "Water.obj", true, true, 40, blue);
	glass->translate(translation);
	myWindow.addMesh(glass);

	translation[0] = -0.5; translation[1] = -0.2; translation[2] = -1; 
	objMesh *cushion = new objMesh("stripes.jpg", "Cushion.obj", true, true, 10, white);
	cushion->scale(scale);
	cushion->rotateX(90);
	cushion->translate(translation);
	myWindow.addMesh(cushion);

	translation[0] = 0.9; 
	objMesh *cushion2 = new objMesh("stripes.jpg", "Cushion.obj", true, true, 10, white);
	cushion2->scale(scale);
	cushion2->rotateX(90);
	cushion2->translate(translation);
	myWindow.addMesh(cushion2);

	myWindow.addMesh(new Wall("brick-background.jpg", 8, 4, 100, red, wall1_lo, wall1_hi) );
	myWindow.addMesh(new Wall("white.jpg", 1, 1, 40, white, wall2_lo, wall2_hi) );
	myWindow.addMesh(new Wall("white.jpg", 1, 1, 40, white, wall3_lo, wall3_hi) );
	myWindow.addMesh(new GROUND("InteriorWoodFlooringMedium_01.jpg", 
					 8, 8, 200, white, floor_lo, floor_hi) );

	glutMainLoop();
}
Ejemplo n.º 2
0
int main(int argc, char *argv[])
{
	QCoreApplication a(argc, argv);

	glfwInit();
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
	glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
	GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "More Cubes", nullptr, nullptr);
	glfwMakeContextCurrent(window);

	glfwSetKeyCallback(window, key_callback);

	glViewport(0, 0, WIDTH, HEIGHT);

	glewExperimental = GL_TRUE;
	glewInit();

	/* Enable depth testing */
	glEnable(GL_DEPTH_TEST);

	Shader myShader("./Resources/default.vs", "./Resources/default.frag");

	GLfloat vertices[] = {
		-0.5f, -0.5f, -0.5f, 0.0f, 0.0f,
		0.5f, -0.5f, -0.5f, 1.0f, 0.0f,
		0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
		0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
		-0.5f, 0.5f, -0.5f, 0.0f, 1.0f,
		-0.5f, -0.5f, -0.5f, 0.0f, 0.0f,

		-0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
		0.5f, -0.5f, 0.5f, 1.0f, 0.0f,
		0.5f, 0.5f, 0.5f, 1.0f, 1.0f,
		0.5f, 0.5f, 0.5f, 1.0f, 1.0f,
		-0.5f, 0.5f, 0.5f, 0.0f, 1.0f,
		-0.5f, -0.5f, 0.5f, 0.0f, 0.0f,

		-0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
		-0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
		-0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
		-0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
		-0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
		-0.5f, 0.5f, 0.5f, 1.0f, 0.0f,

		0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
		0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
		0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
		0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
		0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
		0.5f, 0.5f, 0.5f, 1.0f, 0.0f,

		-0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
		0.5f, -0.5f, -0.5f, 1.0f, 1.0f,
		0.5f, -0.5f, 0.5f, 1.0f, 0.0f,
		0.5f, -0.5f, 0.5f, 1.0f, 0.0f,
		-0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
		-0.5f, -0.5f, -0.5f, 0.0f, 1.0f,

		-0.5f, 0.5f, -0.5f, 0.0f, 1.0f,
		0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
		0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
		0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
		-0.5f, 0.5f, 0.5f, 0.0f, 0.0f,
		-0.5f, 0.5f, -0.5f, 0.0f, 1.0f
	};

	glm::vec3 cubePositions[] = {
		glm::vec3(0.0f, 0.0f, 0.0f),
		glm::vec3(2.0f, 5.0f, -15.0f),
		glm::vec3(-1.5f, -2.2f, -2.5f),
		glm::vec3(-3.8f, -2.0f, -12.3f),
		glm::vec3(2.4f, -0.4f, -3.5f),
		glm::vec3(-1.7f, 3.0f, -7.5f),
		glm::vec3(1.3f, -2.0f, -2.5f),
		glm::vec3(1.5f, 2.0f, -2.5f),
		glm::vec3(1.5f, 0.2f, -1.5f),
		glm::vec3(-1.3f, 1.0f, -1.5f)
	};

	/* VAO, VBO */
	GLuint VBO, VAO;
	glGenVertexArrays(1, &VAO);
	glGenBuffers(1, &VBO);

	glBindVertexArray(VAO);
	glBindBuffer(GL_ARRAY_BUFFER, VBO);
	glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

	/* position attribute */
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (GLvoid*)(0));
	glEnableVertexAttribArray(0);
	/* texture attribute */
	glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));
	glEnableVertexAttribArray(1);

	glBindVertexArray(0);



	/* textures */
	/* texture1 */
	GLuint texture1;
	glGenTextures(1, &texture1);
	glBindTexture(GL_TEXTURE_2D, texture1);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	int width, height;
	unsigned char* image = SOIL_load_image("./Resources/container.jpg", &width, &height, 0, SOIL_LOAD_RGB);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
	glGenerateMipmap(GL_TEXTURE_2D);
	SOIL_free_image_data(image);
	glBindTexture(GL_TEXTURE_2D, 0);

	/* texture2 */
	GLuint texture2;
	glGenTextures(1, &texture2);
	glBindTexture(GL_TEXTURE_2D, texture2);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	image = SOIL_load_image("./Resources/awesomeface.png", &width, &height, 0, SOIL_LOAD_RGB);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
	glGenerateMipmap(GL_TEXTURE_2D);
	SOIL_free_image_data(image);
	glBindTexture(GL_TEXTURE_2D, 0);


	while (!glfwWindowShouldClose(window)){
		glfwPollEvents();

		glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		/* bind texture */
		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, texture1);
		glUniform1i(glGetUniformLocation(myShader.Program, "ourTexture1"), 0);

		glActiveTexture(GL_TEXTURE1);
		glBindTexture(GL_TEXTURE_2D, texture2);
		glUniform1i(glGetUniformLocation(myShader.Program, "ourTexture2"), 1);

		/* active shader */
		myShader.Use();

		/* create transform matrices */
		glm::mat4 view;
		glm::mat4 projection;
		view = glm::translate(view, glm::vec3(0.0f, 0.0f, -3.0f));
		projection = glm::perspective(45.0f, (GLfloat)WIDTH / (GLfloat)HEIGHT, 0.1f, 100.0f);
		/* get their uniform locations */
		GLint modelLoc = glGetUniformLocation(myShader.Program, "model");
		GLint viewLoc = glGetUniformLocation(myShader.Program, "view");
		GLint projectionLoc = glGetUniformLocation(myShader.Program, "projection");
		/* pass them to shader */
		glUniformMatrix4fv(viewLoc, 1, GL_FALSE, glm::value_ptr(view));
		glUniformMatrix4fv(projectionLoc, 1, GL_FALSE, glm::value_ptr(projection));


		glBindVertexArray(VAO);
		for (GLuint i = 0; i < 10; ++i){
			/* 在这里创建model矩阵 */
			glm::mat4 model;
			model = glm::translate(model, cubePositions[i]);
			GLfloat angle = 20.f * i;
			model = glm::rotate(model, angle, glm::vec3(1.0f, 0.3f, 0.5f));
			glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model));

			glDrawArrays(GL_TRIANGLES, 0, 36);

		}
		glBindVertexArray(0);

		glfwSwapBuffers(window);

	}

	glDeleteVertexArrays(1, &VAO);
	glDeleteBuffers(1, &VBO);
	glfwTerminate();

	return a.exec();
}
Ejemplo n.º 3
0
void test_10(){
    ////Test most basic Texturing
    int universeWidth = 720;
    int universeHeight = 480;

    int AmountOfObjects = 3;

    double pixRatio = 50;

    glfwWindowHint(GLFW_SAMPLES, 4);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);

    Universe universe(universeWidth/pixRatio, universeHeight/pixRatio);
    Window window = Window(&universe, pixRatio);

    addRandomObjects(universe,1,AmountOfObjects);
    glClearColor(0.2, 0.2, 0.3, 1.0);


    GLuint Texture = loadDDS("Asteroid.DDS");

    TextureShader myShader(Texture);
    GLuint programID = myShader.programID;
    // Get a handle for our "MVP" uniform
    glm::vec4 colour = {1.0f, 0.0f,0.0f,1.0f};
    CircleShader myCircle(colour);
    //myCircle.colour=colour;
    double size;
    double step = 0.001;
    double phi = 0.003;
    const GLfloat c = cos(phi);
    const GLfloat s = sin(phi);
    glm::mat3 rot = {
            c, -s, 0,
            s,  c, 0,
            0,  0, 1
    };
    do{
        size = cos(step+=0.01);
        myCircle.tMatrixReset();
        myCircle.tMatrixTranslate({size,0.0});
        myCircle.tMatrixScale({size,size});

        myShader.transformationMatrix *= rot;
        // Clear the screen
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        myShader.draw();
        myCircle.draw();
        // Swap buffers
        glfwSwapBuffers(window.GLFWpointer);
        glfwPollEvents();

    } // Check if the ESC key was pressed or the window was closed
    while( glfwGetKey(window.GLFWpointer, GLFW_KEY_ESCAPE ) != GLFW_PRESS &&
           glfwWindowShouldClose(window.GLFWpointer) == 0 );


    // Close OpenGL window and terminate GLFW
    glfwTerminate();
}
Ejemplo n.º 4
0
int main(int argc, char *argv[])
{
	QCoreApplication a(argc, argv);

	glfwInit();
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
	glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
	GLFWwindow* window = glfwCreateWindow(800, 600, "5.0Transformation", NULL, NULL);
	glfwMakeContextCurrent(window);

	glfwSetKeyCallback(window, key_callback);


	

	/* 经测试,下句在使用 core profile 时必须要有,否在在
	   glGenvertexArrays(1, &VAO) 处就会报错 */
	glewExperimental = GL_TRUE;
	glewInit();
	/* glViewprot 和 glewInit() 的顺序无关紧要 */
	glViewport(0, 0, WIDTH, HEIGHT);
	

	Shader myShader("./Resources/default.vs", "./Resources/default.frag");

	GLfloat vertices[] = {
		// Positions          // Colors           // Texture Coords
		0.5f, 0.5f, 0.0f,     1.0f, 0.0f, 0.0f,      1.0f, 1.0f, // Top Right
		0.5f, -0.5f, 0.0f,    0.0f, 1.0f, 0.0f,      1.0f, 0.0f, // Bottom Right
		-0.5f, -0.5f, 0.0f,   0.0f, 0.0f, 1.0f,      0.0f, 0.0f, // Bottom Left
		-0.5f, 0.5f, 0.0f,    1.0f, 1.0f, 0.0f,      0.0f, 1.0f  // Top Left 
	};

	GLuint indices[] = {  // Note that we start from 0!
		0, 1, 3, // First Triangle
		1, 2, 3  // Second Triangle
	};

	/* VAO, VBO, EBO */
	GLuint VAO, VBO, EBO;
	glGenVertexArrays(1, &VAO);
	glGenBuffers(1, &VBO);
	glGenBuffers(1, &EBO);

	
	glBindVertexArray(VAO);

	glBindBuffer(GL_ARRAY_BUFFER, VBO);
	glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);

	/* position attribute */
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*)(0));
	glEnableVertexAttribArray(0);

	/* color attribute */
	glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));
	glEnableVertexAttribArray(1);

	/* texture attribute */
	glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*)(6 * sizeof(GLfloat)));
	glEnableVertexAttribArray(2);

	glBindVertexArray(0);



	/* textures */
	GLuint texture1, texture2;
	/* texture1 */
	glGenTextures(1, &texture1);
	glBindTexture(GL_TEXTURE_2D, texture1);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	int height, width;
	unsigned char* image = SOIL_load_image("./Resources/container.jpg", &width, &height, 0, SOIL_LOAD_RGB);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
	glGenerateMipmap(GL_TEXTURE_2D);
	SOIL_free_image_data(image);
	glBindTexture(GL_TEXTURE_2D, 0);

	/* texture 2*/
	glGenTextures(1, &texture2);
	glBindTexture(GL_TEXTURE_2D, texture2);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	image = SOIL_load_image("./Resources/awesomeface.png", &width, &height, 0, SOIL_LOAD_RGB);
	/* 下面这句少写了,笑脸没有出来,只有第一个文理*/
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
	glGenerateMipmap(GL_TEXTURE_2D);
	SOIL_free_image_data(image);
	glBindTexture(GL_TEXTURE_2D, 0);

	float radians = 90.0*(3.1415926 / 180);
	while (!glfwWindowShouldClose(window)){

		glfwPollEvents();

		glClearColor(0.3f, 0.2f, 0.2f, 1.0f);
		glClear(GL_COLOR_BUFFER_BIT);

		myShader.Use();

		/* bind texture */
		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, texture1);
		glUniform1i(glGetUniformLocation(myShader.Program, "ourTexture1"), 0);

		glActiveTexture(GL_TEXTURE1);
		glBindTexture(GL_TEXTURE_2D, texture2);
		glUniform1i(glGetUniformLocation(myShader.Program, "ourTexture2"), 1);

		/* 创建变化矩阵 */
		// Create transformations
		glm::mat4 model;
		glm::mat4 view;
		glm::mat4 projection;
		model = glm::rotate(model, -55.0f, glm::vec3(1.0f, 0.0f, 0.0f));
		view = glm::translate(view, glm::vec3(0.0f, 0.0f, -3.0f));
		projection = glm::perspective(45.0f, (GLfloat)WIDTH / (GLfloat)HEIGHT, 0.1f, 100.0f);
		// Get their uniform location
		GLint modelLoc = glGetUniformLocation(myShader.Program, "model");
		GLint viewLoc = glGetUniformLocation(myShader.Program, "view");
		GLint projLoc = glGetUniformLocation(myShader.Program, "projection");
		// Pass them to the shaders
		glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model));
		glUniformMatrix4fv(viewLoc, 1, GL_FALSE, glm::value_ptr(view));
		// Note: currently we set the projection matrix each frame, but since the projection matrix rarely changes it's often best practice to set it outside the main loop only once.
		glUniformMatrix4fv(projLoc, 1, GL_FALSE, glm::value_ptr(projection));

		
		/* draw */
		glBindVertexArray(VAO);
		glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
		glBindVertexArray(0);

		glfwSwapBuffers(window);


	}

	glDeleteVertexArrays(1, &VAO);
	glDeleteBuffers(1, &VBO);
	glDeleteBuffers(1, &EBO);
	glfwTerminate();

	return a.exec();
}
Ejemplo n.º 5
0
int main()
{
	WindowBackground myWindow;

	GLint iWindowWidth  = myWindow.getWindowWidth();
	GLint iWindowHeight = myWindow.getWindowHeight();

	SpriteBatch mySprite;

	Texture myTex;

	myTex.loadTexture("E:/Texture/apple.jpg");

	GLint iTexWidth  = myTex.getTexWidth();
	GLint iTexHeight = myTex.getTexHeight();

	GLfloat fTexWidth  = static_cast<GLfloat> (iTexWidth);
	GLfloat fTexHeight = static_cast<GLfloat> (iTexHeight);

	/*FrameBuffer myFBO(iTexWidth, iTexHeight);
	FrameBuffer myFBO2(iTexWidth, iTexHeight);*/

	GLfloat fTime = 0.0f;

	/* Custom shader */
	Shader myShader("VerDny.vs", "FraDny.fs");
	Shader myShader2("VerAve.vs", "FraAve.fs");

	do 
	{
		/* Set context color */
 		glClearColor(1.0f,0.0f,1.0f,0.0f);
 		/* Clear the color buffer */
 		glClear(GL_COLOR_BUFFER_BIT);

		fTime += 0.1f;

		/*Test the custom default*/
		mySprite.setShader(NULL);
		mySprite.begin();
		mySprite.draw(myTex, 0.0f, 0.0f, 0.0f, 0.0f, (GLfloat)iTexWidth, 
		(GLfloat)iTexHeight, 1.0f, 1.0f, 0.0f, 0, 0, iTexWidth, iTexHeight,
		GL_FALSE, GL_FALSE);
		mySprite.end();

		mySprite.setShader(&myShader2);
		mySprite.begin();
		mySprite.draw(myTex, 300.0f, 100.0f, 0.0f, 0.0f, (GLfloat)iTexWidth, 
		(GLfloat)iTexHeight, 1.0f, 1.0f, 0.0f, 0, 0, iTexWidth, iTexHeight, 
		GL_FALSE, GL_FALSE);
		mySprite.end();

		/*Test the FBO*/
		/*mySprite.begin();
		myFBO.begin();
		mySprite.setShader(NULL);
		mySprite.draw(myTex, 0.0f, 0.0f, 0.0f, 0.0f, fTexWidth, 
		fTexHeight, 1.0f, 1.0f, 0.0f, 0, 0, 
		iTexWidth, iTexHeight, GL_FALSE, GL_FALSE);
		myFBO.end(iWindowWidth, iWindowHeight);
		mySprite.draw(myFBO.getRenderTexture(), 300.0f, 0.0f, 0.0f, 0.0f, 
		fTexWidth, fTexHeight, 1.0f, 1.0f, 
		0.0f, 0, 0, iTexWidth, iTexHeight, GL_FALSE, GL_FALSE);
		mySprite.end();

		mySprite.setShader(&myShader);
		mySprite.begin();	
		myShader.setUniformf("time", fTime);
		mySprite.draw(myFBO.getRenderTexture(), 0.0f, 0.0f, 0.0f, 0.0f, 
		fTexWidth, fTexHeight, 1.0f, 1.0f,  
		0.0f, 0, 0, iTexWidth, iTexHeight, GL_FALSE, GL_FALSE);
		mySprite.end();*/

		/*Test the series-shader */
		/*mySprite.begin();
		myFBO.begin();
		mySprite.setShader(NULL);
		mySprite.draw(myTex, 0.0f, 0.0f, 0.0f, 0.0f, fTexWidth, 
		fTexHeight, 1.0f, 1.0f, 0.0f, 0, 0, 
		iTexWidth, iTexHeight, GL_FALSE, GL_FALSE);
		myFBO.end(iWindowWidth, iWindowHeight);*/
		/*mySprite.draw(myFBO.getRenderTexture(), 0.0f, 0.0f, 0.0f, 0.0f, 
		              fTexWidth, fTexHeight, 1.0f, 1.0f, 
		              0.0f, 0, 0, iTexWidth, iTexHeight, GL_FALSE, GL_FALSE);*/
		//mySprite.end();
		
		/* Swap the front and back buffer */
		glfwSwapBuffers(myWindow.getWindowHandle());
		/* Poll events by query */
		glfwPollEvents();

	} while ( 
	    (glfwGetKey(myWindow.getWindowHandle(), GLFW_KEY_ESCAPE) != GLFW_PRESS) 
		&& (glfwWindowShouldClose(myWindow.getWindowHandle()) == 0) 
		);

	/*myFBO.dispose();*/

	/* Release resources */
	mySprite.dispose();

	/* Destroy the window */
	glfwTerminate();

	return 0;

}
Ejemplo n.º 6
0
void init()
{
	// Vertices of a square
	float ext = 1.0;
	float points[NumPoints * 4] = {
		 -ext, -ext,  0, 1.0 , //v1
		  ext, -ext,  0, 1.0 , //v2
		 -ext,  ext,  0, 1.0 , //v3	
		 -ext,  ext,  0, 1.0 , //v3	
		  ext, -ext,  0, 1.0 , //v2
		  ext,  ext,  0, 1.0  //v4
	};

	// Texture coordinates
	float tex_coords[NumPoints * 2] = {
		0.0, 0.0,
		1.0, 0.0,
		0.0, 1.0,
		0.0, 1.0,
		1.0, 0.0,
		1.0, 1.0
	};

	// Initialize texture Objects
	float newFrame[WIN_HEIGHT][WIN_WIDTH][3];

	for(int i=0;i<WIN_HEIGHT;i++)
		for(int j=0;j<WIN_WIDTH;j++){
			newFrame[i][j][0] = frame[i][j].x;
			newFrame[i][j][1] = frame[i][j].y;
			newFrame[i][j][2] = frame[i][j].z;
		}


	GLuint texture;
	glGenTextures( 1, &texture );

	glBindTexture( GL_TEXTURE_2D, texture );


	glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, WIN_WIDTH, WIN_HEIGHT, 0,
		GL_RGB, GL_FLOAT, newFrame );
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
	glActiveTexture( GL_TEXTURE0 );

	// Create and initialize a buffer Object
	GLuint buffer;
	glGenBuffers( 1, &buffer );
	glBindBuffer( GL_ARRAY_BUFFER, buffer );
	glBufferData( GL_ARRAY_BUFFER, sizeof(points) + sizeof(tex_coords), NULL, GL_STATIC_DRAW );
	GLintptr offset = 0;
	glBufferSubData( GL_ARRAY_BUFFER, offset, sizeof(points), points );
	offset += sizeof(points);
	glBufferSubData( GL_ARRAY_BUFFER, offset, sizeof(tex_coords), tex_coords );

	// Load shaders and use the resulting shader program
	Shader myShader( "vshader.glsl", "fshader.glsl" );
	myShader.Use();

	// set up vertex arrays
	offset = 0;
	GLuint vPosition = glGetAttribLocation( myShader.Program, "vPosition" );
	glEnableVertexAttribArray( vPosition );
	glVertexAttribPointer( vPosition, 4, GL_FLOAT, GL_FALSE, 0,
		(GLvoid*) (offset) );

	offset += sizeof(points);
	GLuint vTexCoord = glGetAttribLocation( myShader.Program, "vTexCoord" ); 
	glEnableVertexAttribArray( vTexCoord );
	glVertexAttribPointer( vTexCoord, 2, GL_FLOAT, GL_FALSE, 0,
		(GLvoid*) (offset) );

	glUniform1i( glGetUniformLocation( myShader.Program, "texture"), 0 );

	glClearColor( 1.0, 1.0, 1.0, 1.0 );
}