예제 #1
0
bool MeshGraphicComponent::init()
{
    textureMatrix = mat2(1);

    glDebug();
    if(!shader) {
        Preprocessor *preprocessor = new Preprocessor();
        preprocessor->addVoiceToDictionary("GLSL_VERSION", int(GlobalsManager::Istance()->get("glsl_version") * 100));
        preprocessor->addVoiceToDictionary("MAX_LIGHTS", 10);

        //if(GlobalsManager::Istance()->get("glsl_version")>=3.3)
        shader = new Shader(AssetManager::getBasePath() + "Data/Shader/StaticMesh/Default/shader.vs", AssetManager::getBasePath() + "Data/Shader/NormalMap.fs", preprocessor);
        //else shader=new Shader("Data/Shader/StaticMesh/Default_120/shader.vs","Data/Shader/StaticMesh/Default_120/shader.fs");
        AssetManager::addShader(shader);
        delete preprocessor;
    }
    if(!shader_shadow) {
        Preprocessor *preprocessor = new Preprocessor();
        preprocessor->addVoiceToDictionary("GLSL_VERSION", int(GlobalsManager::Istance()->get("glsl_version") * 100));

        shader_shadow = new Shader(AssetManager::getBasePath() + "Data/Shader/StaticMesh/Shadow/shader.vs", AssetManager::getBasePath() + "Data/Shader/Shadow.fs", preprocessor);
        AssetManager::addShader(shader_shadow);
        delete preprocessor;
    }
    mesh = AssetManager::addStaticMesh(mFilename);
    glDebug();
    if(!mesh) {
        Engine::error(Engine::EString() + "unable to load mesh at : " + mFilename);
        destroy();
        return 0;
    }

    return 1;
}
예제 #2
0
Actor* addMap()
{
	Actor* sphere = new Actor;

	TransformComponent* trans = new TransformComponent();

	trans->setPos(vec3(0, -0.01, 0));
	Rotation rot;
	rot.setEulerAngles(vec3(0, 0.785, 0));
	trans->setRotation(rot);
	sphere->addComponent(trans);
	glDebug();
	sphere->addComponent(new StaticMeshStaticPhysicsComponent(AssetManager::getBasePath() + "Data/Model/mappa4.obj"));
	glDebug();
	MeshGraphicComponent* mesh = new MeshGraphicComponent(AssetManager::getBasePath() + "Data/Model/mappa4.obj");
	glDebug();
	mesh->setTextureMatrix(mat2(scale(mat4(1), vec3(10))));
	glDebug();
	Material *mat = new Material();
	glDebug();
	mat->setDiffuse(AssetManager::getBasePath() + "Data/Texture/floor1_d.png");
	mat->setNormal(AssetManager::getBasePath() + "Data/Texture/floor1_n.png");
	mat->setSpecular(AssetManager::getBasePath() + "Data/Texture/floor1_s.png");
	mat->setShininess(20);
	glDebug();
	mesh->addMaterial(mat);
	glDebug();
	sphere->addComponent(mesh);
	glDebug();
	return sphere;
}
예제 #3
0
Actor* addModel(string filename, vec3 pos = vec3(0), vec3 s = vec3(1))
{

	Actor* sphere = new Actor;

	TransformComponent* trans = new TransformComponent();
	trans->setPos(pos);

	trans->setScale(s);
	sphere->addComponent(trans);
	glDebug();
	sphere->addComponent(new StaticMeshStaticPhysicsComponent(AssetManager::getBasePath() + filename));
	glDebug();
	MeshGraphicComponent* mesh = new MeshGraphicComponent(AssetManager::getBasePath() + filename);
	glDebug();
	mesh->setTextureMatrix(mat2(scale(mat4(1), vec3(10))));
	glDebug();
	Material *mat = new Material();
	glDebug();
	mat->setDiffuse(AssetManager::getBasePath() + "Data/Texture/floor1_d.png");
	mat->setNormal(AssetManager::getBasePath() + "Data/Texture/floor1_n.png");
	mat->setSpecular(AssetManager::getBasePath() + "Data/Texture/floor1_s.png");
	mat->setShininess(20);
	glDebug();
	mesh->addMaterial(mat);
	glDebug();
	sphere->addComponent(mesh);
	glDebug();
	return sphere;
}
예제 #4
0
void
xlCamOrtho(void)
{
	XLcamera *bind = xlGetCamera();
	XLCameraProperty *property = &bind->body.properties[bind->runtime.property];
	XLreal left, right, bottom, top;

	if(property->details.orthogonal.left == XL_REAL(0) && property->details.orthogonal.right == XL_REAL(0) && property->details.orthogonal.bottom == XL_REAL(0) && property->details.orthogonal.top == XL_REAL(0))
	{
		left = xlGetInteger(XL_VIEWPORT_PROPERTY_X);
		top = xlGetInteger(XL_VIEWPORT_PROPERTY_Y);
		right = xlGetInteger(XL_VIEWPORT_PROPERTY_WIDTH);
		bottom = xlGetInteger(XL_VIEWPORT_PROPERTY_HEIGHT);
	}
	else
	{
		left = property->details.orthogonal.left;
		right = property->details.orthogonal.right;
		bottom = property->details.orthogonal.bottom;
		top = property->details.orthogonal.top;
	}

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	//gluOrtho2D(property->details.orthogonal.left, property->details.orthogonal.right, property->details.orthogonal.bottom, property->details.orthogonal.top);
	//FIXME: do xlMatrixOrho2D
	gluOrtho2D(left, right, bottom, top);
	glGetFloatv(GL_PROJECTION_MATRIX, XL_MATRIX_ARRAY(&property->projection));
	glMatrixMode(GL_MODELVIEW);

	glDebug(__FILE__, __LINE__);
}
예제 #5
0
MeshGraphicComponent::MeshGraphicComponent(string filename)
{
    glDebug();
    mFilename = filename;
    mesh = 0;
    //shader = 0;
    flag.add("castShadow");
    init();
}
예제 #6
0
void
xlVptProperty(void)
{
	XLviewport *bind = xlGetViewport();
	XLViewportProperty *property = &bind->body.properties[bind->runtime.property];

	glViewport(XL_PAIR_X(&property->position), XL_PAIR_Y(&property->position), XL_PAIR_X(&property->size), XL_PAIR_Y(&property->size)); 

	glDebug(__FILE__, __LINE__);
}
예제 #7
0
void
xlOpEnd(void)
{
	//XLoperator *bind = xlGetOperator();

	glPopMatrix();
	//glMatrixMode(GL_MODELVIEW);

	glDebug(__FILE__, __LINE__);
}
예제 #8
0
void
xlCamEnd(void)
{
	//XLcamera *bind = xlGetCamera();
	//XLCameraProperty *property = &bind->body.properties[bind->runtime.property];

	glPopMatrix();
	//glMatrixMode(GL_MODELVIEW);

	glDebug(__FILE__, __LINE__);
}
예제 #9
0
void MeshGraphicComponent::bindRenderState(RenderParameter &param)
{
    glDebug();
    if(param.flag & RenderFlag::Default) {
        if(shader) {
            shader->Use();
            glDebug();
        }
        glEnableVertexAttribArray(0);
        glEnableVertexAttribArray(1);
        glEnableVertexAttribArray(2);
        glEnableVertexAttribArray(3);
    } else if(param.flag & RenderFlag::Shadow) {
        if(shader_shadow) {
            shader_shadow->Use();
            glDebug();
        }
        glEnableVertexAttribArray(0);
    }
}
예제 #10
0
void
xlSurfEnd(void)
{
	//XLsurface *bind = xlGetSurface();

	glPopAttrib();

	glMatrixMode(GL_TEXTURE);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);

	glDebug(__FILE__, __LINE__);
}
예제 #11
0
void
xlOpBegin(void)
{
	XLcamera *camera = xlGetCamera();
	XLCameraProperty *property = &camera->body.properties[camera->runtime.property];

	xlGetOpMatrix(&property->modelview);

	//glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glMultMatrixf(XL_MATRIX_ARRAY(&property->modelview));

	glDebug(__FILE__, __LINE__);
}
예제 #12
0
void
xlCamBegin(void)
{
	XLcamera *bind = xlGetCamera();
	XLCameraProperty *property = &bind->body.properties[bind->runtime.property];

	xlMatrixAssignCopy(&property->modelview, &property->matrix);

	//glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glMultMatrixf(XL_MATRIX_ARRAY(&property->modelview));

	glDebug(__FILE__, __LINE__);
}
예제 #13
0
Actor* addLucy(Scene* scene)
{
	string tex[] = {"#666666", "#666667", "#666668", "#666669"};
	for(int i = 0; i < 5; i++) {
		Actor* sphere = new Actor;

		vec3 pos(i * 3, 0, -25);
		TransformComponent* trans = new TransformComponent();
		trans->setScale(vec3(0.2));
		trans->setPos(pos);
		sphere->addComponent(trans);
		glDebug();
		sphere->addComponent(new SpherePhysicsComponent(1));
		glDebug();
		MeshGraphicComponent* mesh = new MeshGraphicComponent(AssetManager::getBasePath() + "Data/Model/lucy_low.obj");
		glDebug();
		mesh->setTextureMatrix(mat2(scale(mat4(1), vec3(10))));
		glDebug();
		Material *mat = new Material();
		glDebug();

		if(i) {
			mat->setDiffuse(tex[i - 1]);
			mat->setShininess(i * i * i * i);
		} else {
			mat->setDiffuse(AssetManager::getBasePath() + "Data/Texture/floor1_d.png");
			mat->setNormal(AssetManager::getBasePath() + "Data/Texture/floor1_n.png");
			mat->setSpecular(AssetManager::getBasePath() + "Data/Texture/floor1_s.png");
			mat->setShininess(20);
		}
		glDebug();
		mesh->addMaterial(mat);
		glDebug();
		sphere->addComponent(mesh);
		glDebug();


		scene->addActor(sphere);
	}
	return 0;
}
예제 #14
0
void
xlSurfBegin(void)
{
	XLmaterial *material;
	XLMaterialProperty *property;
	XLmatrix matrix;

	xlSurfMaterial();
	material = xlGetMaterial();
	property = &material->body.properties[material->runtime.property];

	xlGetSurfMatrix(&matrix);
	glMatrixMode(GL_TEXTURE);
	glPushMatrix();
	glMultMatrixf(XL_MATRIX_ARRAY(&matrix));
	glMatrixMode(GL_MODELVIEW);

	glPushAttrib(GL_DEPTH_BUFFER_BIT);

	if(property->alpha == XL_REAL(1)) glDepthMask(GL_TRUE);
	else glDepthMask(GL_FALSE);

	glDebug(__FILE__, __LINE__);
}
예제 #15
0
void
xlCamPerspective(void)
{
	XLcamera *bind = xlGetCamera();
	XLCameraProperty *property = &bind->body.properties[bind->runtime.property];
	XLreal aspect;

	if(property->details.perspective.aspect == XL_REAL(0))
	{
		aspect = XL_REAL(xlGetInteger(XL_VIEWPORT_PROPERTY_WIDTH)) / XL_REAL(xlGetInteger(XL_VIEWPORT_PROPERTY_HEIGHT));
	}
	else
		aspect = property->details.perspective.aspect;

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	//gluPerspective(property->details.perspective.fovy, property->details.perspective.aspect, property->details.perspective.znear, property->details.perspective.zfar);
	//FIXME: do xlMatrixPerspective
	gluPerspective(property->details.perspective.fovy, aspect, property->details.perspective.znear, property->details.perspective.zfar);
	glGetFloatv(GL_PROJECTION_MATRIX, XL_MATRIX_ARRAY(&property->projection));
	glMatrixMode(GL_MODELVIEW);

	glDebug(__FILE__, __LINE__);
}
예제 #16
0
void SkeletalMeshGraphicComponent::unitDraw(RenderParameter &param)//Actor *actor,Engine::Scene* scene)
{

    glDebug();
    TransformComponent* trans = 0;
    if(m_pOwner)trans = m_pOwner->getComponent<TransformComponent>(ComponentId::Transform);

    //glPushMatrix();
    glColor3f(0, 1, 0);


    Shader* currentShader = 0;
    if(param.flag & RenderFlag::Default)currentShader = shader;
    else if(param.flag & RenderFlag::Shadow)currentShader = shader_shadow;


    if(currentShader) {
        currentShader->Use();
        glDebug();
        GLuint p = currentShader->getProgramId();
        int loc;
        glDebug();
        if(trans) {
            loc=currentShader->getUniformLocation("MVM");
            if(loc>=0)glUniformMatrix4fv(loc, 1, 0, &trans->getMatrix()[0][0]);

        }
        glDebug(param.flag);
        loc=currentShader->getUniformLocation("textureMatrix");
        if(param.flag & RenderFlag::Default)if(loc>-1)glUniformMatrix2fv(loc, 1, 0, &textureMatrix[0][0]);



        glDebug(param.flag);
        mesh->updateUniform(currentShader->getProgramId());
        mesh->draw(materials, currentShader,param.flag);
        glDebug();

    }


    //glPopMatrix();
}