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);
}
openGL es 2.0 一般工程步骤
最新推荐文章于 2020-06-29 16:25:38 发布