openGL es 2.0 一般工程步骤

void Mountain::drawSelf()
{
	
	// calculate state
	//	Matrix::matrixTranslateM(gModelMatrix,
	//			0.0f, -1.0f, 0.0f);
	tempValue+=1;
	setLightDirection(0,50,0);

	Matrix::matrixMultiplyMM(gMVPMatrix, Matrix::getInstance()->gViewMatrix,
			gModelMatrix);
	Matrix::matrixMultiplyMM(gMVPMatrix,
			Matrix::getInstance()->gProjectionMatrix, gMVPMatrix);

	//
	// setup openGL state
	// Render State ...

	
	glEnable(GL_BLEND);
	glBlendEquation(GL_FUNC_ADD); // glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	// Textures State.., 0-7
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, m_texture);

	// Shader States ..
	glUseProgram(gProgram);
	glUniformMatrix4fv(gMVPMatrixHandle, 1, GL_FALSE, gMVPMatrix);
	glUniformMatrix4fv(gMMatrixHandle,1,GL_FALSE, gModelMatrix);
	glUniform3fv(uLightDirectionHandle,1, lightDirection);
	glUniform1i(gTexHandle, 0);

	// Vertex buffer, Indices Buffer
	glEnableVertexAttribArray(gPositionHandle);
	glBindBuffer(GL_ARRAY_BUFFER,vertexBuffer);
	glVertexAttribPointer(gPositionHandle, POSITION_DATA_SIZE, GL_FLOAT,
			GL_FALSE, 0,(void*)0);

	glEnableVertexAttribArray(gNormalHandle);
	glBindBuffer(GL_ARRAY_BUFFER,nomalBuffer);
	glVertexAttribPointer(gNormalHandle, POSITION_DATA_SIZE, GL_FLOAT,
			GL_FALSE, 0,(void*)0);

	glEnableVertexAttribArray(gTexCoorHandle);
	glBindBuffer(GL_ARRAY_BUFFER,textureBuffer);
	glVertexAttribPointer(gTexCoorHandle, 2, GL_FLOAT,
			GL_FALSE, 0,(void*)0);

	// Draws
	glDrawArrays(GL_TRIANGLES, 0, vCount);

	//
	// restore step
	glBindBuffer(GL_ARRAY_BUFFER, 0);

	glDisableVertexAttribArray(gPositionHandle);
	glDisableVertexAttribArray(gTexCoorHandle);
	glDisableVertexAttribArray(gNormalHandle);

	glUseProgram(0);

	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, 0);

	glDisable(GL_BLEND);
	glBlendEquation(GL_FUNC_ADD); // glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值