static void draw() { static int i = 0; i++; Matrix modelview; /* clear the color buffer */ glClearColor(0.5, 0.5, 0.5, 1.0); glClear(GL_COLOR_BUFFER_BIT); MatrixLoadIdentity(&modelview); Translate(&modelview, 0.0f, 0.0f, -8.0f); Rotate(&modelview, 45.0f + (0.25f * i), 1.0f, 0.0f, 0.0f); Rotate(&modelview, 45.0f - (0.5f * i), 0.0f, 1.0f, 0.0f); Rotate(&modelview, 10.0f + (0.15f * i), 0.0f, 0.0f, 1.0f); GLfloat aspect = 512/512; Matrix projection; MatrixLoadIdentity(&projection); Frustum(&projection, -2.8f, +2.8f, -2.8f * aspect, +2.8f * aspect, 6.0f, 10.0f); Matrix modelviewprojection; MatrixLoadIdentity(&modelviewprojection); MatrixMultiply(&modelviewprojection, &modelview, &projection); float normal[9]; normal[0] = modelview.m[0][0]; normal[1] = modelview.m[0][1]; normal[2] = modelview.m[0][2]; normal[3] = modelview.m[1][0]; normal[4] = modelview.m[1][1]; normal[5] = modelview.m[1][2]; normal[6] = modelview.m[2][0]; normal[7] = modelview.m[2][1]; normal[8] = modelview.m[2][2]; glUniformMatrix4fv(modelviewmatrix, 1, GL_FALSE, &modelview.m[0][0]); glUniformMatrix4fv(modelviewprojectionmatrix, 1, GL_FALSE, &modelviewprojection.m[0][0]); glUniformMatrix3fv(normalmatrix, 1, GL_FALSE, normal); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, cubePositions); GLint texCoordLoc = glGetAttribLocation(program, "a_texCoord"); glEnableVertexAttribArray(texCoordLoc); glVertexAttribPointer(texCoordLoc, 2, GL_FLOAT, GL_FALSE, 0, cubeTexels); glDrawArrays(GL_TRIANGLES, 0, cubeVertices); }
static void draw() { static int i = 0; i++; Matrix modelview; /* clear the color buffer */ glClearColor(0.5, 0.5, 0.5, 1.0); glClear(GL_COLOR_BUFFER_BIT); MatrixLoadIdentity(&modelview); Translate(&modelview, 0.0f, 0.0f, -8.0f); Rotate(&modelview, 45.0f + (0.25f * i), 1.0f, 0.0f, 0.0f); Rotate(&modelview, 45.0f - (0.5f * i), 0.0f, 1.0f, 0.0f); Rotate(&modelview, 10.0f + (0.15f * i), 0.0f, 0.0f, 1.0f); GLfloat aspect = 512/512; Matrix projection; MatrixLoadIdentity(&projection); Frustum(&projection, -2.8f, +2.8f, -2.8f * aspect, +2.8f * aspect, 6.0f, 10.0f); Matrix modelviewprojection; MatrixLoadIdentity(&modelviewprojection); MatrixMultiply(&modelviewprojection, &modelview, &projection); float normal[9]; normal[0] = modelview.m[0][0]; normal[1] = modelview.m[0][1]; normal[2] = modelview.m[0][2]; normal[3] = modelview.m[1][0]; normal[4] = modelview.m[1][1]; normal[5] = modelview.m[1][2]; normal[6] = modelview.m[2][0]; normal[7] = modelview.m[2][1]; normal[8] = modelview.m[2][2]; glUniformMatrix4fv(modelviewmatrix, 1, GL_FALSE, &modelview.m[0][0]); glUniformMatrix4fv(modelviewprojectionmatrix, 1, GL_FALSE, &modelviewprojection.m[0][0]); glUniformMatrix3fv(normalmatrix, 1, GL_FALSE, normal); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDrawArrays(GL_TRIANGLE_STRIP, 4, 4); glDrawArrays(GL_TRIANGLE_STRIP, 8, 4); glDrawArrays(GL_TRIANGLE_STRIP, 12, 4); glDrawArrays(GL_TRIANGLE_STRIP, 16, 4); glDrawArrays(GL_TRIANGLE_STRIP, 20, 4); }
void GrGLPathRendering::resetContext() { fHWProjectionMatrixState.invalidate(); // we don't use the model view matrix. GL_CALL(MatrixLoadIdentity(GR_GL_PATH_MODELVIEW)); fHWPathStencilSettings.invalidate(); }
void GrGLPathRendering::resetContext() { fHWProjectionMatrixState.invalidate(); // we don't use the model view matrix. GrGLenum matrixMode = fGpu->glStandard() == kGLES_GrGLStandard ? GR_GL_PATH_MODELVIEW : GR_GL_MODELVIEW; GL_CALL(MatrixLoadIdentity(matrixMode)); if (!caps().fragmentInputGenSupport) { for (int i = 0; i < fGpu->glCaps().maxFixedFunctionTextureCoords(); ++i) { GL_CALL(PathTexGen(GR_GL_TEXTURE0 + i, GR_GL_NONE, 0, NULL)); fHWPathTexGenSettings[i].fMode = GR_GL_NONE; fHWPathTexGenSettings[i].fNumComponents = 0; } fHWActivePathTexGenSets = 0; } fHWPathStencilSettings.invalidate(); }
static void draw() { Matrix modelview; static const GLfloat vVertices[] = { // front -1.0f, -1.0f, +1.0f, // point blue +1.0f, -1.0f, +1.0f, // point magenta -1.0f, +1.0f, +1.0f, // point cyan +1.0f, +1.0f, +1.0f, // point white // back +1.0f, -1.0f, -1.0f, // point red -1.0f, -1.0f, -1.0f, // point black +1.0f, +1.0f, -1.0f, // point yellow -1.0f, +1.0f, -1.0f, // point green // right +1.0f, -1.0f, +1.0f, // point magenta +1.0f, -1.0f, -1.0f, // point red +1.0f, +1.0f, +1.0f, // point white +1.0f, +1.0f, -1.0f, // point yellow // left -1.0f, -1.0f, -1.0f, // point black -1.0f, -1.0f, +1.0f, // point blue -1.0f, +1.0f, -1.0f, // point green -1.0f, +1.0f, +1.0f, // point cyan // top -1.0f, +1.0f, +1.0f, // point cyan +1.0f, +1.0f, +1.0f, // point white -1.0f, +1.0f, -1.0f, // point green +1.0f, +1.0f, -1.0f, // point yellow // bottom -1.0f, -1.0f, -1.0f, // point black +1.0f, -1.0f, -1.0f, // point red -1.0f, -1.0f, +1.0f, // point blue +1.0f, -1.0f, +1.0f // point magenta }; static const GLfloat vColors[] = { // front 0.0f, 0.0f, 1.0f, // blue 1.0f, 0.0f, 1.0f, // magenta 0.0f, 1.0f, 1.0f, // cyan 1.0f, 1.0f, 1.0f, // white // back 1.0f, 0.0f, 0.0f, // red 0.0f, 0.0f, 0.0f, // black 1.0f, 1.0f, 0.0f, // yellow 0.0f, 1.0f, 0.0f, // green // right 1.0f, 0.0f, 1.0f, // magenta 1.0f, 0.0f, 0.0f, // red 1.0f, 1.0f, 1.0f, // white 1.0f, 1.0f, 0.0f, // yellow // left 0.0f, 0.0f, 0.0f, // black 0.0f, 0.0f, 1.0f, // blue 0.0f, 1.0f, 0.0f, // green 0.0f, 1.0f, 1.0f, // cyan // top 0.0f, 1.0f, 1.0f, // cyan 1.0f, 1.0f, 1.0f, // white 0.0f, 1.0f, 0.0f, // green 1.0f, 1.0f, 0.0f, // yellow // bottom 0.0f, 0.0f, 0.0f, // black 1.0f, 0.0f, 0.0f, // red 0.0f, 0.0f, 1.0f, // blue 1.0f, 0.0f, 1.0f // magenta }; static const GLfloat vNormals[] = { // front +0.0f, +0.0f, +1.0f, // forward +0.0f, +0.0f, +1.0f, // forward +0.0f, +0.0f, +1.0f, // forward +0.0f, +0.0f, +1.0f, // forward // back +0.0f, +0.0f, -1.0f, // backbard +0.0f, +0.0f, -1.0f, // backbard +0.0f, +0.0f, -1.0f, // backbard +0.0f, +0.0f, -1.0f, // backbard // right +1.0f, +0.0f, +0.0f, // right +1.0f, +0.0f, +0.0f, // right +1.0f, +0.0f, +0.0f, // right +1.0f, +0.0f, +0.0f, // right // left -1.0f, +0.0f, +0.0f, // left -1.0f, +0.0f, +0.0f, // left -1.0f, +0.0f, +0.0f, // left -1.0f, +0.0f, +0.0f, // left // top +0.0f, +1.0f, +0.0f, // up +0.0f, +1.0f, +0.0f, // up +0.0f, +1.0f, +0.0f, // up +0.0f, +1.0f, +0.0f, // up // bottom +0.0f, -1.0f, +0.0f, // down +0.0f, -1.0f, +0.0f, // down +0.0f, -1.0f, +0.0f, // down +0.0f, -1.0f, +0.0f // down }; static const GLfloat vTexUVs[] = { // front 0.1f, 0.9f, 0.9f, 0.9f, 0.1f, 0.1f, 0.9f, 0.1f, // back 0.1f, 0.9f, 0.9f, 0.9f, 0.1f, 0.1f, 0.9f, 0.1f, // right 0.1f, 0.9f, 0.9f, 0.9f, 0.1f, 0.1f, 0.9f, 0.1f, // left 0.1f, 0.9f, 0.9f, 0.9f, 0.1f, 0.1f, 0.9f, 0.1f, // top 0.1f, 0.9f, 0.9f, 0.9f, 0.1f, 0.1f, 0.9f, 0.1f, // bottom 0.1f, 0.9f, 0.9f, 0.9f, 0.1f, 0.1f, 0.9f, 0.1f, }; /* clear the color buffer */ glClearColor(0.5, 0.5, 0.5, 1.0); glClear(GL_COLOR_BUFFER_BIT); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vVertices); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, vNormals); glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, vColors); glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, 0, vTexUVs); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glEnableVertexAttribArray(2); glEnableVertexAttribArray(3); float distance = 8.0; static int i = 0; i++; MatrixLoadIdentity(&modelview); Translate(&modelview, 0.0f, 0.0f, -distance); Rotate(&modelview, 45.0f + (0.25f * i), 1.0f, 0.0f, 0.0f); Rotate(&modelview, 45.0f - (0.5f * i), 0.0f, 1.0f, 0.0f); Rotate(&modelview, 10.0f + (0.15f * i), 0.0f, 0.0f, 1.0f); GLfloat aspect = 512/512; float fov = 45; Matrix projection; MatrixLoadIdentity(&projection); Perspective(&projection, fov, aspect, 1.0f, 10.0f); Matrix modelviewprojection; MatrixLoadIdentity(&modelviewprojection); MatrixMultiply(&modelviewprojection, &modelview, &projection); float normal[9]; normal[0] = modelview.m[0][0]; normal[1] = modelview.m[0][1]; normal[2] = modelview.m[0][2]; normal[3] = modelview.m[1][0]; normal[4] = modelview.m[1][1]; normal[5] = modelview.m[1][2]; normal[6] = modelview.m[2][0]; normal[7] = modelview.m[2][1]; normal[8] = modelview.m[2][2]; glUniformMatrix4fv(modelviewmatrix, 1, GL_FALSE, &modelview.m[0][0]); glUniformMatrix4fv(modelviewprojectionmatrix, 1, GL_FALSE, &modelviewprojection.m[0][0]); glUniformMatrix3fv(normalmatrix, 1, GL_FALSE, normal); glEnable(GL_CULL_FACE); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDrawArrays(GL_TRIANGLE_STRIP, 4, 4); glDrawArrays(GL_TRIANGLE_STRIP, 8, 4); glDrawArrays(GL_TRIANGLE_STRIP, 12, 4); glDrawArrays(GL_TRIANGLE_STRIP, 16, 4); glDrawArrays(GL_TRIANGLE_STRIP, 20, 4); }