Beispiel #1
0
void Shader::DrawMesh(Mesh *mesh, glm::mat4 model)
{
    // Set model matrix
    safe_glUniformMatrix4fv(modelMatrixHandle, glm::value_ptr(model));

    safe_glEnableVertexAttribArray(positionHandle);
    glBindBuffer(GL_ARRAY_BUFFER, mesh->PositionHandle);
    safe_glVertexAttribPointer(positionHandle, 3, GL_FLOAT, GL_FALSE, 0, 0);

    safe_glEnableVertexAttribArray(normalHandle);
    glBindBuffer(GL_ARRAY_BUFFER, mesh->NormalHandle);
    safe_glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, 0);

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mesh->IndexHandle);

    glUniform3f(lightHandle.Position, light.Position.x, light.Position.y,
                light.Position.z);
    glUniform3f(lightHandle.Color, light.Color.x, light.Color.y, light.Color.z);

    loadMaterial();

    glDrawElements(GL_TRIANGLES, mesh->IndexBufferLength, GL_UNSIGNED_SHORT, 0);

    safe_glDisableVertexAttribArray(positionHandle);
    safe_glDisableVertexAttribArray(normalHandle);
}
Beispiel #2
0
/* Main display function */
void Draw (void)
{
   glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

   //Start our shader   
   glUseProgram(ShadeProg);
   
   SetModelI();
   /* Set up the projection and view matrices */
   SetProjectionMatrix();
   SetView();

   /* Set up the light's direction and color */
   glUniform3f(h_uLightColor, sunShade.x, sunShade.y, sunShade.z);
   glUniform3f(h_uSun, sunDir.x, sunDir.y, sunDir.z);

   // set the normal flag
   glUniform1i(h_uShadeType, g_shadeType);

 // ======================== draw square stuff =========================

      drawModel(&bunnyModel);

 // ================== end of bird stuff ====================

   //clean up 
   safe_glDisableVertexAttribArray(h_aPosition);
   safe_glDisableVertexAttribArray(h_aNormal);

   //disable the shader
   glUseProgram(0);
}
Beispiel #3
0
void World::draw(int mountainSide)
{
	safe_glEnableVertexAttribArray(handles->aPosition);
	safe_glEnableVertexAttribArray(handles->aNormal);
   
   glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
   mount.draw();

   for (int i = 0; i < objectsToDraw.size(); i++) {
      objectsToDraw.at(i)->draw();
   }
   
   //clean up
   safe_glDisableVertexAttribArray(handles->aPosition);
   safe_glDisableVertexAttribArray(handles->aNormal);
}
Beispiel #4
0
void DrawShadow(float x, float z, float Sx, float Sy, float Sz, float angle) {
    /*Shadow*/
    SetModel(x, -0.5, z, Sx, Sy, Sz, angle);
    SetMaterial(1);
    safe_glEnableVertexAttribArray(h_aPosition);
    glBindBuffer(GL_ARRAY_BUFFER, ShadowCubeBuffObj);
    safe_glVertexAttribPointer(h_aPosition, 3, GL_FLOAT, GL_FALSE, 0, 0);

    safe_glEnableVertexAttribArray(h_aNormal);
    glBindBuffer(GL_ARRAY_BUFFER, ShadowNormalBuffObj);
    safe_glVertexAttribPointer(h_aNormal, 3, GL_FLOAT, GL_FALSE, 0, 0);

    /* draw!*/
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, SCIndxBuffObj);
    glDrawElements(GL_TRIANGLES, g_SCiboLen, GL_UNSIGNED_SHORT, 0);

    /* Disable the attributes used by our shader*/
    safe_glDisableVertexAttribArray(h_aPosition);
    safe_glDisableVertexAttribArray(h_aNormal);
}
Beispiel #5
0
void SetupCube(float x, float y, float z, int material, float angle, float scaleX, float scaleY, float scaleZ) {
    /*First Cube*/
    SetModel(x, y, z, scaleX, scaleY, scaleZ, angle);
    SetMaterial(material);
    safe_glEnableVertexAttribArray(h_aPosition);
    glBindBuffer(GL_ARRAY_BUFFER, CubeBuffObj);
    safe_glVertexAttribPointer(h_aPosition, 3, GL_FLOAT, GL_FALSE, 0, 0);

    safe_glEnableVertexAttribArray(h_aNormal);
    glBindBuffer(GL_ARRAY_BUFFER, NormalBuffObj);
    safe_glVertexAttribPointer(h_aNormal, 3, GL_FLOAT, GL_FALSE, 0, 0);

    /* draw!*/
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, CIndxBuffObj);

    glDrawElements(GL_TRIANGLES, g_CiboLen, GL_UNSIGNED_SHORT, 0);

    /* Disable the attributes used by our shader*/
    safe_glDisableVertexAttribArray(h_aPosition);
    safe_glDisableVertexAttribArray(h_aNormal);
//   DrawShadow(x, z + 0.6, scaleX, scaleY, scaleZ + 0.4, angle);
}
Beispiel #6
0
/* Main display function */
void Draw (void)
{
	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);				
	//Start our shader	
 	glUseProgram(ShadeProg);

	//data set up to access the vertices and color
  	safe_glEnableVertexAttribArray(h_aPosition);
 	glBindBuffer(GL_ARRAY_BUFFER, triBuffObj);
	safe_glVertexAttribPointer(h_aPosition, 4, GL_FLOAT, GL_FALSE, 0, 0);
  	safe_glEnableVertexAttribArray(h_aColor);
 	glBindBuffer(GL_ARRAY_BUFFER, colBuffObj);
	safe_glVertexAttribPointer(h_aColor, 3, GL_FLOAT, GL_FALSE, 0, 0);

	//actually draw the data
	glDrawArrays(GL_TRIANGLES, 0, 9);
													
	//clean up 
	safe_glDisableVertexAttribArray(h_aPosition);
	safe_glDisableVertexAttribArray(h_aColor);
	//disable the shader
	glUseProgram(0);	
	glutSwapBuffers();
}
Beispiel #7
0
/* Main display function */
void glfwDraw (GLFWwindow *window)
{
    ModelTrans.loadIdentity();
    SetModelStat();

    safe_glEnableVertexAttribArray(h_aPosition);

    glBindBuffer(GL_ARRAY_BUFFER, GrndBuffObj);
    safe_glVertexAttribPointer(h_aPosition, 3, GL_FLOAT, GL_FALSE, 0, 0);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, GIndxBuffObj);

    SetMaterial(0);

    safe_glEnableVertexAttribArray(h_aNormal);
    glBindBuffer(GL_ARRAY_BUFFER, GNBuffObj);
    safe_glVertexAttribPointer(h_aNormal, 3, GL_FLOAT, GL_FALSE, 0, 0);

    /* draw!*/
    glDrawElements(GL_TRIANGLES, g_GiboLen, GL_UNSIGNED_SHORT, 0);
    safe_glDisableVertexAttribArray(h_aPosition);

    //DRAW THE DANCING CYLINDER HERE!!
    btTransform pla;
    PlaceModel(playerMesh, GetLookAt().x, GetLookAt().y - 1, GetLookAt().z, .25, .1, .25, 1);
    //END OF DANCING CYLINDER CODE HERE!!
    SetMaterial(2);
    drawSelectedObject();
    drawEntities();

    //Draw Cubes, ??????????
    SetupCube(plsRndr().getX(),plsRndr().getY(),plsRndr().getZ(),5,60,1,1,1);
    for(float i=.05; i<1; i+=.0075) {
        srand(physGetPlayerX());
        float x = physGetPlayerX()*(1-i)+grapplingHookLocation().x*i;
        float y = physGetPlayerY()*(1-i)*(1-i)+grapplingHookLocation().y*i*i;
        float z = physGetPlayerZ()*(1-i)+grapplingHookLocation().z*i;
        SetupCube(x,y,z,5,rand()/300.0,.15,.15,.15);
    }

    SetMaterial(2);

    //draw phys cubes
    vector<btRigidBody*> loopable = getVecList();
    srand(0);
    for(int i = 0; i<loopable.size(); i++) {
        btTransform trans;
        loopable[i]->getMotionState()->getWorldTransform(trans);
        //printf("actual is %f %f %f\n",trans.getOrigin().getX(),trans.getOrigin().getY(),trans.getOrigin().getZ());

        if(!i)
            PlaceModel(*(Mesh*)(loopable[i]->getUserPointer()), trans.getOrigin().getX(),trans.getOrigin().getY(),trans.getOrigin().getZ(),.15*SCALE,-.05*SCALE,.15*SCALE,1);
        else
            PlaceModel(*(Mesh*)(loopable[i]->getUserPointer()), trans.getOrigin().getX(),trans.getOrigin().getY(),trans.getOrigin().getZ(),.1*SCALE,.1*SCALE,.1*SCALE, 0);
        // SetupCube(trans.getOrigin().getX(),trans.getOrigin().getY(),trans.getOrigin().getZ(),2,0,2,2,2);
    }


    ///render spherse
    /*
       btTransform trans;
       fallRigidBody->getMotionState()->getWorldTransform(trans);
       std::cout << "sphere height: " << trans.getOrigin().getY() << " sphere x:"<<trans.getOrigin().getX()<< " sphere z:"<< trans.getOrigin().getZ() <<std::endl;
       SetupCube(trans.getOrigin().getX(),trans.getOrigin().getY(),trans.getOrigin().getZ(),2,60,2,2,2);
       fallRigidBodyb->getMotionState()->getWorldTransform(trans);
       SetupCube(trans.getOrigin().getX(),trans.getOrigin().getY(),trans.getOrigin().getZ(),2,60,2,2,2);
       FRBbuilding->getMotionState()->getWorldTransform(trans);
       SetupCube(trans.getOrigin().getX(),trans.getOrigin().getY(),trans.getOrigin().getZ(),3,0,2,2,2);
    */
}