Пример #1
0
void render() {

    if (initialized == false) {
        glEnable(GL_CULL_FACE);
        glEnable(GL_DEPTH_TEST);
        spherePositionsId = createSpherePositions();
        sphereNormalsId = createSphereNormals(positions);
        createProgram();
        startTimeMillis = currentTimeMillis();
        initialized = true;
    }

    frameCount++;
    totalFrameCount++;
    long now = currentTimeMillis();
    long elapsed = now - startTimeMillis;
    static long lastTimerCall = 0;
    if ((now - lastTimerCall) > 250) {
        timer(0);
        lastTimerCall = now;
    }

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glUseProgram(programId);

    //
    // calculate the ModelViewProjection and ModelViewProjection matrices
    //
    matrix44 tmp, mv, mvp, frustumMat, translateMat, rotateMat1, rotateMat2;
    frustum(frustumMat, left, right, bottom / aspectRatio, top / aspectRatio, nearPlane, farPlane);
    translate(translateMat, 0.0f, 0.0f, -3.0f);
    rotate(rotateMat1, 1.0f * elapsed / 50, 1.0f, 0.0f, 0.0f);
    rotate(rotateMat2, 1.0f * elapsed / 100, 0.0f, 1.0f, 0.0f);
    multm(tmp, rotateMat1, rotateMat2);
    multm(mv, translateMat, tmp);
    multm(mvp, frustumMat, mv);

    // set the uniforms before rendering
    GLuint mvpMatrixUniform = glGetUniformLocation(programId, "mvpMatrix");
    GLuint mvMatrixUniform = glGetUniformLocation(programId, "mvMatrix");
    GLuint colorUniform = glGetUniformLocation(programId, "color");
    GLuint ambientUniform = glGetUniformLocation(programId, "ambient");
    GLuint lightDirUniform = glGetUniformLocation(programId, "lightDir");
    glUniformMatrix4fv(mvpMatrixUniform, 1, false, mvp);
    glUniformMatrix4fv(mvMatrixUniform, 1, false, mv);
    glUniform3f(lightDirUniform, 1.0f, -1.0f, -1.0f);
    glUniform4f(colorUniform, 0.5f, 0.5f, 0.5f, 1.0f);
    glUniform4f(ambientUniform, 0.1f, 0.1f, 0.1f, 1.0f);

    // render!
    renderSphere();

    // display rendering buffer
    SDL_GL_SwapBuffers();
}
Пример #2
0
/*=============================================================================
Function expm

Purpose:  take a number to a power mod m
          
Parameters:
     ul a (IN) - first operand
     ul b (IN) - second operand
     ul m (IN) - modulus

Returns:  a to power b mod m
=============================================================================*/
ul expm(ul a, ul b, ul m) {
  ul mask = 0x80000000;
  ul i;
  ul t=1;
  for (i=0;i<32;i++) {
    t = multm(t,t,m);
    if (b&mask) t=multm(t,a,m);
    mask>>=1;
  }
  return t;
}