Exemplo n.º 1
0
int Init ( ESContext *esContext )
{
	glClearColor ( 0.0f, 0.0f, 0.0f, 0.0f );

	//triangle data (heap)
	Vertex verticesData[3];
	RotationMatrix.SetIdentity();
	verticesData[0].pos.x =  0.0f;  verticesData[0].pos.y =  0.5f;  verticesData[0].pos.z =  0.0f;
	verticesData[1].pos.x = -0.5f;  verticesData[1].pos.y = -0.5f;  verticesData[1].pos.z =  0.0f;
	verticesData[2].pos.x =  0.5f;  verticesData[2].pos.y = -0.5f;  verticesData[2].pos.z =  0.0f;

	verticesData[0].color.x = 0.5f;  verticesData[0].color.y = 1.0f;  verticesData[0].color.z = 0.3f;
	verticesData[1].color.x = 0.0f;  verticesData[1].color.y = 0.3f;  verticesData[1].color.z = 0.0f;
	verticesData[2].color.x = 0.1f;  verticesData[2].color.y = 0.1f;  verticesData[2].color.z = 0.3f;

	//buffer object
	glGenBuffers(1, &vboId); //buffer object name generation
	glBindBuffer(GL_ARRAY_BUFFER, vboId); //buffer object binding
	glBufferData(GL_ARRAY_BUFFER, sizeof(verticesData), verticesData, GL_STATIC_DRAW); //creation and initializion of buffer onject storage
	glBindBuffer(GL_ARRAY_BUFFER, 0);

	//creation of shaders and program 
	return myShaders.Init("../Resources/Shaders/TriangleShaderVS.vs", "../Resources/Shaders/TriangleShaderFS.fs");

}
Exemplo n.º 2
0
int _tmain(int argc, _TCHAR* argv[])
{
	ESContext esContext;

    esInitContext ( &esContext );

	esCreateWindow ( &esContext, "Hello Model", Globals::screenWidth, Globals::screenHeight, ES_WINDOW_RGB | ES_WINDOW_DEPTH);

	if ( Init ( &esContext ) != 0 )
		return 0;

	if (ppShaders.Init("../Resources/Shaders/PPShaderVS.vs", "../Resources/Shaders/PPShaderFS.fs") != 0)
		return 0;

	esRegisterDrawFunc ( &esContext, Draw );
	esRegisterUpdateFunc ( &esContext, Update );
	esRegisterKeyFunc ( &esContext, Key);

	esMainLoop ( &esContext );

	//releasing OpenGL resources
	CleanUp();

	//identifying memory leaks
	MemoryDump();
	printf("Press any key...\n");
	_getch();

	return 0;
}
int Init ( ESContext *esContext )
{
	glClearColor ( 0.0f, 0.0f, 0.0f, 1.0f );
	glEnable(GL_DEPTH_TEST);

	//triangle data (heap)
	FILE *pFile;
	fopen_s(&pFile, "../Resources/Models/Woman1.nfg", "r");
	fscanf_s(pFile, "NrVertices: %d", &vertices);
	Vertex *verticesData = new Vertex[vertices];
	for (int i = 0; i<vertices; i++) {
		fscanf_s(pFile, " %*d. pos:[%f, %f, %f]; norm:[%*f, %*f, %*f]; binorm:[%*f, %*f, %*f]; tgt:[%*f, %*f, %*f]; uv:[%f, %f]; ", &verticesData[i].pos.x, &verticesData[i].pos.y, &verticesData[i].pos.z, &verticesData[i].uv.x, &verticesData[i].uv.y);
	}

	//buffer object
	glGenBuffers(1, &vboId); //buffer object name generation
	glBindBuffer(GL_ARRAY_BUFFER, vboId); //buffer object binding
	glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex)*vertices, verticesData, GL_STATIC_DRAW); //creation and initializion of buffer onject storage
	glBindBuffer(GL_ARRAY_BUFFER, 0);

	fscanf_s(pFile, "NrIndices: %d", &indices);
	Index *indicesData = new Index[indices];
	for (int i = 0; i<indices/3; i++) {
		fscanf_s(pFile, " %*d. %u, %u, %u ", &indicesData[i].x, &indicesData[i].y, &indicesData[i].z);
	}
	
	glGenBuffers(1, &iboId);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, iboId);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned short)*indices, indicesData, GL_STATIC_DRAW);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

	fclose(pFile);

	glGenTextures(1, &textureHandle);
	glBindTexture(GL_TEXTURE_2D, textureHandle);
	int width, height, bpp;
	char* bufferTGA = LoadTGA("../Resources/Textures/Woman1.tga", &width, &height, &bpp);

	if (bpp == 24) {
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, bufferTGA);
	}
	else {
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, bufferTGA);
	}
	delete []bufferTGA;

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glGenerateMipmap(GL_TEXTURE_2D);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

	delete []verticesData;
	delete []indicesData;
	//creation of shaders and program 
	return myShaders.Init("../Resources/Shaders/TriangleShaderVS.vs", "../Resources/Shaders/TriangleShaderFS.fs");

}
Exemplo n.º 4
0
int Init ( ESContext *esContext )
{
	glClearColor ( 0.7f, 0.7f, 0.7f, 1.0f );

	int result = myShaders.Init("../Resources/Shaders/TriangleShaderVS.vs", "../Resources/Shaders/TriangleShaderFS.fs");
	int resultFire = myFireShader.Init("../Resources/Shaders/FireSample.vs", "../Resources/Shaders/FireSample.fs");
	int resultLighted = myShadersLighted.Init("../Resources/Shaders/ModelsLighted.vs", "../Resources/Shaders/ModelsLighted.fs");

	mySprite.Init("../../NewResourcesPacket/Models/Croco.nfg", myShaders.GetShaderInfo());
	mySpriteLighted.Init("../../NewResourcesPacket/Models/Croco.nfg", myShadersLighted.GetShaderInfo());
	//mySprite.Init("../../NewResourcesPacket/Models/Marine.nfg", myShaders.GetShaderInfo());
	//mySprite.Init("../../NewResourcesPacket/Models/Woman1.nfg", myShaders.GetShaderInfo());
	myFireEffect.Init("../../NewResourcesPacket/Models/fire.nfg", myFireShader.GetShaderInfo());
	
	mySprite.SetPosition(Vector3(300, 0, 0));
	mySpriteLighted.SetPosition(Vector3(-300, 0, 0));

	return result&&resultFire&&resultLighted;
}
Exemplo n.º 5
0
int Init ( ESContext *esContext )
{
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glEnable(GL_DEPTH_TEST);
	m.SetIdentity();

	woman.loadModel("../Resources/Models/Woman1.nfg");
	woman.loadTexture("../Resources/Textures/Woman1.tga");

	//creation of shaders and program 
	return myShaders.Init("../Resources/Shaders/TriangleShaderVS.vs", "../Resources/Shaders/TriangleShaderFS.fs");

}
int Init ( ESContext *esContext )
{
	glClearColor ( 0.0f, 0.0f, 0.0f, 0.0f );

	//triangle data (heap)
	Vertex verticesData[3];

	verticesData[0].pos.x =  0.0f;  verticesData[0].pos.y =  0.5f;  verticesData[0].pos.z =  0.0f;
	verticesData[1].pos.x = -0.5f;  verticesData[1].pos.y = -0.5f;  verticesData[1].pos.z =  0.0f;
	verticesData[2].pos.x =  0.5f;  verticesData[2].pos.y = -0.5f;  verticesData[2].pos.z =  0.0f;
	
	verticesData[0].color.x = 1.0f;  verticesData[0].color.y = 0.0f; verticesData[0].color.z = 0.0f;
	verticesData[1].color.x = 0.0f;  verticesData[1].color.y = 1.0f;  verticesData[1].color.z = 0.0f;
	verticesData[2].color.x = 0.0f; verticesData[2].color.y = 0.0f; verticesData[2].color.z = 1.0f;

	//buffer object
	glGenBuffers(1, &vboId);
	glBindBuffer(GL_ARRAY_BUFFER, vboId);
	glBufferData(GL_ARRAY_BUFFER, sizeof(verticesData), verticesData, GL_STATIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, 0);

	glGenTextures(1, &textureHandle);
	glBindTexture(GL_TEXTURE_2D, textureHandle);
	int width, height, bpp;
	char* bufferTGA = LoadTGA("../Resources/Textures/Grass.tga", &width, &height, &bpp);
	if (bpp == 24) {
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, bufferTGA);
	}
	else {
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, bufferTGA);
	}
	delete[] bufferTGA;

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glGenerateMipmap(GL_TEXTURE_2D);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	//creation of shaders and program 
	return myShaders.Init("../Resources/Shaders/TriangleShaderVS.vs", "../Resources/Shaders/TriangleShaderFS.fs");

}
Exemplo n.º 7
0
int Init ( ESContext *esContext )
{
	glClearColor ( 0.0f, 0.0f, 0.0f, 1.0f );
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glDisable(GL_CULL_FACE);

	//triangle data (heap)
	FILE *pFile;
	fopen_s(&pFile, "../Resources/Models/Terrain.nfg", "r");
	fscanf_s(pFile, "NrVertices: %d", &vertices);
	Vertex *verticesData = new Vertex[vertices];
	for (int i = 0; i<vertices; i++) {
		fscanf_s(pFile, " %*d. pos:[%f, %f, %f]; norm:[%*f, %*f, %*f]; binorm:[%*f, %*f, %*f]; tgt:[%*f, %*f, %*f]; uv:[%f, %f]; ", &verticesData[i].pos.x, &verticesData[i].pos.y, &verticesData[i].pos.z, &verticesData[i].uv.x, &verticesData[i].uv.y);
	}
		
	//buffer object
	glGenBuffers(1, &vboId); //buffer object name generation
	glBindBuffer(GL_ARRAY_BUFFER, vboId); //buffer object binding
	glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex)*vertices, verticesData, GL_STATIC_DRAW); //creation and initializion of buffer onject storage
	glBindBuffer(GL_ARRAY_BUFFER, 0);

	fscanf_s(pFile, "NrIndices: %d", &indices);
	Index *indicesData = new Index[indices];
	for (int i = 0; i<indices/3; i++) {
		fscanf_s(pFile, " %*d. %u, %u, %u ", &indicesData[i].x, &indicesData[i].y, &indicesData[i].z);
	}
	
	glGenBuffers(1, &iboId);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, iboId);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned short)*indices, indicesData, GL_STATIC_DRAW);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

	fclose(pFile);
	
	Helper::loadTexture(&textureHandle, "../Resources/Textures/Rock.tga");
	Vector3 modelPivot = Helper::getModelPivot(vertices, verticesData);
	modelMatrix.SetIdentity();
	modelMatrix.SetTranslation(-modelPivot.x, -modelPivot.y, -modelPivot.z);
	modelMatrix = modelMatrix * modelMatrix.SetRotationX(90.0f);
	viewMatrix = camera.GetViewMatrix();
	projectionMatrix.SetPerspective(45.0f, float(Globals::screenWidth) / float(Globals::screenHeight), 0.1f, 500.0f);
	
	transformMatrix = modelMatrix * viewMatrix * projectionMatrix;

	delete []verticesData;
	delete []indicesData;

	//FBO
	glGenFramebuffers(1, &framebuffer);
	glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
	glGenTextures(1, &colorTex);
	glBindTexture(GL_TEXTURE_2D, colorTex);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	//NULL means reserve texture memory, but texels are undefined
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Globals::screenWidth, Globals::screenHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
	glBindTexture(GL_TEXTURE_2D, 0);
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorTex, 0);
	glBindFramebuffer(GL_FRAMEBUFFER, 0);

	Vertex quadData[6];

	quadData[0].pos.x = -1.0f;  quadData[0].pos.y = 1.0f;  quadData[0].pos.z = 0.0f;
	quadData[1].pos.x = -1.0f;  quadData[1].pos.y = -1.0f;  quadData[1].pos.z = 0.0f;
	quadData[2].pos.x = 1.0f;  quadData[2].pos.y = -1.0f;  quadData[2].pos.z = 0.0f;
	quadData[3].pos.x = -1.0f;  quadData[3].pos.y = 1.0f;  quadData[3].pos.z = 0.0f;
	quadData[4].pos.x = 1.0f;  quadData[4].pos.y = -1.0f;  quadData[4].pos.z = 0.0f;
	quadData[5].pos.x = 1.0f;  quadData[5].pos.y = 1.0f;  quadData[5].pos.z = 0.0f;

	quadData[0].uv.x = 0.0f;	quadData[0].uv.y = 1.0f;
	quadData[1].uv.x = 0.0f;	quadData[1].uv.y = 0.0f;
	quadData[2].uv.x = 1.0f;	quadData[2].uv.y = 0.0f;
	quadData[3].uv.x = 0.0f;	quadData[3].uv.y = 1.0f;
	quadData[4].uv.x = 1.0f;	quadData[4].uv.y = 0.0f;
	quadData[5].uv.x = 1.0f;	quadData[5].uv.y = 1.0f;


	//buffer object
	glGenBuffers(1, &vboQuad); //buffer object name generation
	glBindBuffer(GL_ARRAY_BUFFER, vboQuad); //buffer object binding
	glBufferData(GL_ARRAY_BUFFER, sizeof(quadData), quadData, GL_STATIC_DRAW); //creation and initializion of buffer onject storage
	glBindBuffer(GL_ARRAY_BUFFER, 0);

	//creation of shaders and program 
	return myShaders.Init("../Resources/Shaders/ShaderVS.vs", "../Resources/Shaders/ShaderFS.fs");

}