Пример #1
0
Entity::Entity(string name, string fileName){
    this->name = name;
    this->fileName = fileName;

    vertices = NULL;
    indices = NULL;
    normals = NULL;

    vboVertices = NULL;
    vboIndices = NULL;
    vboNormals = NULL;

    shaderProgram = NULL ;
    vertexShader = NULL ;
    fragmentShader = NULL ;

    textureCoordinates = NULL;
    tangents = NULL;

    readMeshXml();
    readMaterial();
    generateTangents();

    createVBOs();

    transformation.setToIdentity() ;

    live = true;
}
bool GLES2Lesson::init(float w, float h, const std::string &vertexShader,
                       const std::string &fragmentShader) {

    printVerboseDriverInformation();

    gProgram = createProgram(vertexShader.c_str(), fragmentShader.c_str());

    if (!gProgram) {
        LOGE("Could not create program.");
        return false;
    }

    fetchShaderLocations();

    glViewport(0, 0, w, h);
    checkGlError("glViewport");

    projectionMatrix = glm::perspective(45.0f, w / h, 0.1f, 100.0f);

    createVBOs();

    textureId = uploadTextureData(textureData, textureWidth, textureHeight);

    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    glFrontFace(GL_CW);
    glDepthMask(true);
    return true;
}
    bool GLES2Lesson::init(float w, float h, const std::string &vertexShader,
                           const std::string &fragmentShader) {

        printVerboseDriverInformation();

        gProgram = createProgram(vertexShader.c_str(), fragmentShader.c_str());

        if (!gProgram) {
            LOGE("Could not create program.");
            return false;
        }

        fetchShaderLocations();

        glViewport(0, 0, w, h);
        checkGlError("glViewport");

        projectionMatrix = glm::perspective(45.0f, w / h, 0.1f, 1024.0f);

        createVBOs();

        glActiveTexture(GL_TEXTURE0);
        textureId = uploadTextureData(textureData, textureWidth, textureHeight);
        glActiveTexture(GL_TEXTURE1);
        twinkleId = uploadTextureData(twinkleData, textureWidth, textureHeight);
        initStars();

        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE);
        glFrontFace(GL_CW);
        glDepthMask(true);

        return true;
    }
Пример #4
0
void main(int argc, char **argv){
	//Read in TLEs and Initialize SGP4
	std::ifstream tle_file("D:\\School\\cis565\\cis565-project\\src\\SGP4\\SGP4\\catalog_3l_2012_03_26_am.txt");
	twolineelement2rv(tle_file, SatRec);
	numberSatellites = SatRec.size();
	initSGP4(wgs84, SatRec, numberSatellites);

	SatRec.erase(SatRec.begin(), SatRec.end());

	glutInit(&argc, argv);
    glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE );
    glutInitWindowSize( window_width, window_height);
    glutCreateWindow( " SGP4 CPU ");

	    // initialize GL
    if( false == initGL()) {
        return;
    }

    // register callbacks
    glutDisplayFunc( display);
    glutKeyboardFunc( keyboard);
    glutMouseFunc( mouse);
    glutMotionFunc( motion);
	glutIdleFunc( idle);
	
    // create VBO
    createVBOs( vbo_pos );

    glutMainLoop();
	return;
}
    bool GLES2Lesson::init(float w, float h, const std::string &vertexShader,
                           const std::string &fragmentShader) {

        printVerboseDriverInformation();

        gProgram = createProgram(vertexShader.c_str(), fragmentShader.c_str());

        if (!gProgram) {
            LOGE("Could not create program.");
            return false;
        }

        fetchShaderLocations();

        glViewport(0, 0, w, h);
        checkGlError("glViewport");

        projectionMatrix = glm::perspective(45.0f, w / h, 0.1f, 100.0f);

        createVBOs();

        glActiveTexture(GL_TEXTURE0);
        textureId = uploadTextureData(textureData, textureWidth, textureHeight);


        enableAlphaBlending();
        return true;
    }
Пример #6
0
void GLC_MeshData::setVboUsage(bool usage)
{
	if (usage && (m_PositionSize != -1) && (!m_Positions.isEmpty()) && (!m_VertexBuffer.isCreated()))
	{
		createVBOs();

		fillVbo(GLC_MeshData::GLC_Vertex);
		fillVbo(GLC_MeshData::GLC_Normal);
		fillVbo(GLC_MeshData::GLC_Texel);
		fillVbo(GLC_MeshData::GLC_Color);
		useVBO(false, GLC_MeshData::GLC_Color);

		const int lodCount= m_LodList.count();
		for (int i= 0; i < lodCount; ++i)
		{
			m_LodList.at(i)->setIboUsage(usage);
		}

	}
	else if (!usage && m_VertexBuffer.isCreated())
	{
		m_Positions= positionVector();
		m_PositionSize= m_Positions.size();
		m_VertexBuffer.destroy();

		m_Normals= normalVector();
		m_NormalBuffer.destroy();

		if (m_TexelBuffer.isCreated())
		{
			m_Texels= texelVector();
			m_TexelsSize= m_Texels.size();
			m_TexelBuffer.destroy();
		}
		if (m_ColorBuffer.isCreated())
		{
			m_Colors= colorVector();
			m_ColorSize= m_Colors.size();
			m_ColorBuffer.destroy();
		}

		const int lodCount= m_LodList.count();
		for (int i= 0; i < lodCount; ++i)
		{
			m_LodList.at(i)->setIboUsage(usage);
		}
	}
	m_UseVbo= usage;

}
Пример #7
0
void GameWindow::initGL() {
    glewInit();

    createVBOs();
    createShaders();

    texture.load("life_cell.bmp");

    worldLocation = glGetUniformLocation(shaderProgram.getGLProgram(), "world");
    assert(worldLocation != 0xFFFFFFFF);

    stateLocation = glGetUniformLocation(shaderProgram.getGLProgram(), "cellState");
    assert(stateLocation != 0xFFFFFFFF);

    samplerLocation = glGetUniformLocation(shaderProgram.getGLProgram(), "sampler");
    assert(samplerLocation != 0xFFFFFFFF);
    glUniform1i(samplerLocation, 0);
}
Пример #8
0
bool SpriteMeshLoader::loadSpriteMesh( string filename, string meshID ){


    //check if meshID already exists!
    if (renderer->vboList[meshID]){
        renderer->vboList.erase(meshID);
        }

    // XML File Open

    cout << "Loading file..." << filename <<endl;

    TiXmlDocument doc( filename );
    if (!doc.LoadFile()) return false;

    TiXmlHandle hDoc(&doc);
    TiXmlElement * element;
    TiXmlHandle hRoot(0);

    //***********************************************************************
    //Skip over first Element
    //***********************************************************************
    element=hDoc.FirstChildElement().Element();
    // should always have a valid root but handle gracefully if it doesn't
    if (!element) return false;

    // save this for later
    hRoot=TiXmlHandle(element);
    //end XML file open;

    //setup new MeshData
    MeshData* myMesh=new MeshData;
    myMesh->bIsSkeletal=false;
    myMesh->bIsHead=false;
    myMesh->bVertexColor=true;
    myMesh->boneCount=0;
    myMesh->texCoordPerVertexCount=3;
    myMesh->verticesPerShapeCount=4;
    myMesh->vertexInterpretation=GL_POINTS;
    myMesh->drawType=DRAW_VBOMESH;
    renderer->vboList[meshID]=myMesh;


    loadVertices(meshID, hRoot.FirstChild("vertices").Element());
    loadNormals(meshID, hRoot.FirstChild("normals").Element());
    loadTexCoords(meshID, hRoot.FirstChild("texCoords").Element());

    loadColors(meshID, hRoot.FirstChild("colors").Element());
    loadSecondaryColors(meshID, hRoot.FirstChild("secondaryColors").Element());

    loadBoneReferences(meshID, hRoot.FirstChild("boneReferences").Element());
    loadVertexWeights(meshID, hRoot.FirstChild("vertexWeights").Element());

    cout << "loading bones..." << endl;

    loadBones(meshID, hRoot.FirstChild("bone").Element());


	//fill vertex data for editing
	if (!renderer->vboList[meshID]->vData.empty())
		renderer->vboList[meshID]->vData.clear();

	for (int i=0;i<vertexCount;i++){
        vertexData myVData;
        myVData.location=vertices[i];
        myVData.normal=normals[i];
        myVData.color=colors[i];
        myVData.secondaryColor=secondaryColors[i];
        myVData.birth=0.0f;
        myVData.texCoord=texCoords[i];
        myVData.vertexWeights=vertexWeights[i];
        myVData.boneReferences=boneReference[i];
        renderer->vboList[meshID]->vData.push_back(myVData);
    }

    cout << "before creating vbos..." << endl;


    createVBOs(meshID);

    cout << "after creating vbos..." << endl;


   //now free our resources:
	delete(vertices);
	delete(normals);
	delete(texCoords);
	delete(colors);
	delete(secondaryColors);
	delete(vertexWeights);
	delete(boneReference);

    doc.Clear();

    cout << "finished loading SpriteMesh" << endl;

    return true;
}