Пример #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);
}
Пример #2
0
void drawModel(Model * model) {
   SetModel(model);

   safe_glEnableVertexAttribArray(h_aPosition);
   glBindBuffer(GL_ARRAY_BUFFER, model->vbo);
   safe_glVertexAttribPointer(h_aPosition, 3, GL_FLOAT, GL_FALSE, 0, 0);
    
   safe_glEnableVertexAttribArray(h_aNormal);
   glBindBuffer(GL_ARRAY_BUFFER, model->nbo);
   safe_glVertexAttribPointer(h_aNormal, 3, GL_FLOAT, GL_FALSE, 0, 0);

   glDrawArrays(GL_TRIANGLES, 0, model->faceCount);
}
Пример #3
0
/*struct part{
   void move(float step, part* thing);
   void create(float step, part* thing);
   void destroy(float step, part* thing);

   glm::mat4 (*getPos)();
   float scatter;
   int amount;
   float transp;
   int seed;

   int posBuff;
   glm::vec3[] pos;

   int norBuff;
   glm::vec3[] normal;

   int sizVbo;
   float[] size;

   glm::vec3[] velocity;
glm::vec3[] ambientColor;
}*/
void drawPart(part* thing){
      thing->age++;
      thing->move(1.0,thing);
      glPointSize(10);
      //printf("draw a part\n");
      //
      SetModel(0,0,0,1,1,1,0);
      SetMaterial(thing->mat);//7
      //SetMaterial(18);//7
      glBindBuffer(GL_ARRAY_BUFFER, thing->posBuff);
      float* pointdata = (float*)glMapBuffer(GL_ARRAY_BUFFER,GL_READ_WRITE);
      for(int i=0;i<thing->amount;i++){
         //printf("orig %f %f %f\n",data[i],data[i+1],data[i+2]);
         //printf("%f %f %f is pos of e part\n",thing->pos[i].x,thing->pos[i].x,thing->pos[i].x);
         vec3 tmp = thing->pos[i];
         pointdata[i*3+0] = tmp.x;
         pointdata[i*3+1] = tmp.y;
         pointdata[i*3+2] = tmp.z;
         //printf("now  %f %f %f\n",data[i],data[i+1],data[i+2]);
      }
      glUnmapBuffer(GL_ARRAY_BUFFER);

      glBindBuffer(GL_ARRAY_BUFFER, thing->sizBuff);
      float* sizedata = (float*)glMapBuffer(GL_ARRAY_BUFFER,GL_READ_WRITE);
      for(int i=0;i<thing->amount;i++){
         //printf("psize is %f\n",sizedata[i]);
         sizedata[i] = thing->size[i];
      }
      glUnmapBuffer(GL_ARRAY_BUFFER);

      //set transforms to idents
      safe_glEnableVertexAttribArray(h_aPosition);
      glBindBuffer(GL_ARRAY_BUFFER, thing->posBuff);
      safe_glVertexAttribPointer(h_aPosition, 3, GL_FLOAT, GL_FALSE, 0, 0);

      safe_glEnableVertexAttribArray(h_aNormal);
      glBindBuffer(GL_ARRAY_BUFFER, thing->norBuff);
      safe_glVertexAttribPointer(h_aNormal, 3, GL_FLOAT, GL_FALSE, 0, 0);

      safe_glEnableVertexAttribArray(h_aPointSize);
      glBindBuffer(GL_ARRAY_BUFFER, thing->sizBuff);
      safe_glVertexAttribPointer(h_aPointSize, 1, GL_FLOAT, GL_FALSE, 0, 0);

      //printf("the buff is h_aPointSize %d\n",h_aPointSize);

      //draw
      glBindBuffer(GL_ARRAY_BUFFER, thing->posBuff);
      //printf("the amt is %d\n",thing->amount);
      glDrawArrays(GL_POINTS,0, thing->amount);

}
Пример #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);
}
Пример #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);
}
Пример #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();
}
Пример #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);
    */
}