void RenderScene()
{
	// Model matrix : being updated by idle
	// Our ModelViewProjection : multiplication of our 3 matrices
	MVP = Projection * View * Model; // Remember, matrix multiplication is the other way around

	// Use our shader
	glUseProgram(ShaderMainProgramId);

	// Send our transformation to the currently bound shader, in the "MVP" uniform

	glUniformMatrix4fv(MainShaderMvpId, 1, GL_FALSE, &MVP[0][0]);

	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

	// Bind texture to texture unit
	glActiveTexture(GL_TEXTURE0); // change active texture unit to number 0
	glBindTexture(GL_TEXTURE_2D, TextureId); // bind the texture to the active texture unit (which is now 0)

	// Bind shader variable "Texture" to texture unit
	glUniform1iARB(MainShaderTextureId, 0); // Notice the 0 to indicate you want to sample from the texture bound to Texture Unit GL_TEXTURE0.

	float imageRatio = (float)theTexMap.GetNumCols() / theTexMap.GetNumRows();
	if (imageRatio > 1)
	{
		imageRatio = 1.0 / imageRatio;
	}

	glBegin(GL_QUADS);

	glTexCoord2f(0.0, 1.0);
	glVertex3f(-1.0, 0.0, -1.0*imageRatio);

	glTexCoord2f(0.0, 0.0);
	glVertex3f(-1.0, 0.0, 1.0*imageRatio);

	glTexCoord2f(1.0, 0.0);
	glVertex3f(1.0, 0.0, 1.0*imageRatio);

	glTexCoord2f(1.0, 1.0);
	glVertex3f(1.0, 0.0, -1.0*imageRatio);

	glEnd();


	// Draw groups
	glUseProgram(ShaderModelProgramId);
	glUniformMatrix4fv(ModelShaderMvpId, 1, GL_FALSE, &MVP[0][0]);

	int modelNum = 0;
	for (std::vector<Group>::iterator it = (*Data).begin(); it != (*Data).end(); ++it)
	{
		RenderGroup(it->items, it->color, modelNum++);
		RenderGroupCount(it->items.size(), 0);
	}
	glutWarpPointer(g_iWindowWidth/2, g_iWindowHeight/2);
}
Beispiel #2
0
 void createTexture(){
     glGenTextures(1, &textureMap[0]);
     glBindTexture(GL_TEXTURE_2D, textureMap[0]);
     imagMap.LoadBmpFile(groundTexture); /* Passar a string para const char em C */
     glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
     glTexImage2D(GL_TEXTURE_2D, 0, 3,
         imagMap.GetNumCols(),
         imagMap.GetNumRows(), 0, GL_RGB, GL_UNSIGNED_BYTE,
         imagMap.ImageData());
 }
Beispiel #3
0
void Surface::loadTexture(string im_path) {
    RgbImage image;

    glGenTextures(1, &texture);
    glBindTexture(GL_TEXTURE_2D, texture);
    image.LoadBmpFile(im_path.c_str());
    glTexImage2D(GL_TEXTURE_2D,
                 0,
                 3,
                 image.GetNumCols(),
                 image.GetNumRows(), 0, GL_RGB, GL_UNSIGNED_BYTE,
                 image.ImageData() );
    glBindTexture(GL_TEXTURE_2D, 0); // deactivate
}
void LoadResources()
{
	// Load file
	Data = ParseFile("A01.txt");




	// Load texture
	// Let OpenGL create us a new texture ID to use
	glGenTextures(1, &TextureId);

	// Bind against the texture ID
	glBindTexture(GL_TEXTURE_2D, TextureId);

	// Set properties on current bound texture
	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_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);

	// Load texture data
	auto h = gluBuild2DMipmaps(GL_TEXTURE_2D, 3, theTexMap.GetNumCols(), theTexMap.GetNumRows(), GL_RGB, GL_UNSIGNED_BYTE, theTexMap.ImageData());
	//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, theTexMap.GetNumCols(), theTexMap.GetNumRows(), 0, GL_RGB, GL_UNSIGNED_BYTE, theTexMap.ImageData());





	// Create and compile our GLSL program from the shaders
	ShaderMainProgramId = LoadShaders("Main.vertexshader", "Main.fragmentshader");
	ShaderModelProgramId = LoadShaders("Model.vertexshader", "Model.fragmentshader");

	MainShaderMvpId = glGetUniformLocation(ShaderMainProgramId, "MVP");
	MainShaderTextureId = glGetUniformLocation(ShaderMainProgramId, "Texture");

	ModelShaderMvpId = glGetUniformLocation(ShaderModelProgramId, "MVP");
	ModelShaderColorId = glGetUniformLocation(ShaderModelProgramId, "Color");





	// Upload and bind vertexes/indices
	Vertex vertices[8] = {
		{ 0.0f*0.05, 1.0f*0.05, 0.0f*0.05 },
		{ 0.0f*0.05, 1.0f*0.05, 1.0f*0.05 },
		{ 1.0f*0.05, 1.0f*0.05, 1.0f*0.05 },
		{ 1.0f*0.05, 1.0f*0.05, 0.0f*0.05 },
		{ 0.0f*0.05, 0.0f*0.05, 0.0f*0.05 },
		{ 0.0f*0.05, 0.0f*0.05, 1.0f*0.05 },
		{ 1.0f*0.05, 0.0f*0.05, 1.0f*0.05 },
		{ 1.0f*0.05, 0.0f*0.05, 0.0f*0.05 }
	};

	GLubyte indices[36] = {
		0, 3, 7,
		5, 7, 0,
		4, 0, 7,
		0, 3, 7,
		7, 3, 6,
		3, 2, 6,
		6, 2, 5,
		2, 1, 5,
		5, 1, 4,
		1, 0, 4,
		5, 4, 6,
		4, 7, 6
	};

	// Vertex buffer
	glGenBuffers(1, &VertexBufferId);
	glBindBuffer(GL_ARRAY_BUFFER, VertexBufferId);
	glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

	// Index buffer
	glGenBuffers(1, &IndexBufferId);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IndexBufferId);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
}