Exemplo n.º 1
0
int main(int argc, char **argv)
{

    Engine* engine = new Engine();
    engine->Init();

    engine->GetShader_Manager()->CreateProgram("cubeShader",
            "Shaders\\Cube_Vertex_Shader.glsl",
            "Shaders\\Cube_Fragment_Shader.glsl");

    CubeTexture* cube = new CubeTexture();
    int program = engine->GetShader_Manager()->GetShader("cubeShader");
    if (program != 0)
    {
        cube->SetProgram(program);
        cube->Create();
    }
    else
    {
        std::cout << "invalid program...";
        std::cin.get();
    }
    unsigned int texture = engine->GetTexture_Loader()->LoadTexture("Textures\\Crate.bmp", 256, 256);
    cube->SetTexture("Create",texture);

    engine->GetModels_Manager()->SetModel("cube", cube);

    engine->Run();

    delete engine;
    return 0;
}
Exemplo n.º 2
0
	CubeTextureFace::CubeTextureFace(CubeTexture &cubeTex,unsigned int faceId) : m_cubeTex(cubeTex),
																				 m_faceId(faceId % 6)
	{
		m_size = fm::vec2(cubeTex.getSize(),cubeTex.getSize());
		m_isRepeated = cubeTex.isRepeated();
		m_isSmooth   = cubeTex.isSmooth();
		getGlId()    = m_cubeTex.getGlId();
	}
Exemplo n.º 3
0
//=======================================================================================
//		public method
//=======================================================================================
//-------------------------------------------------------------
//!	@brief		: example
//!	@param[in]	: example
//!	@return		: example
//-------------------------------------------------------------
ITexture* CubeTextureFactory::CreateTexture()
{
	CubeTexture* out = NEW CubeTexture();

	IDirect3DCubeTexture9* tex = NULL;

	out->SetTexture(&tex);

	return out;
}
Exemplo n.º 4
0
//-------------------------------------------------------------
//!	@brief		: example
//!	@param[in]	: example
//!	@return		: example
//-------------------------------------------------------------
ITexture* CubeTextureFactory::CreateTextureFromFile(const std::string& filePath)
{
	CubeTexture* out = NEW CubeTexture();

	IDirect3DCubeTexture9* tex = NULL;

	USES_CONVERSION;

	D3DXCreateCubeTextureFromFile(
		GraphicsManager::GetInstance()->GetD3DDevice(),
		A2W(filePath.c_str()),
		&tex);

	out->SetTexture(&tex);
	return out;
}
Exemplo n.º 5
0
	fm::Result CubeTextureFace::copyFace(const CubeTexture &cubeTex,unsigned int face)
	{
		CubeTextureFace tmpFace(m_cubeTex,face);
		tmpFace.getGlId() = cubeTex.getGlId();
		tmpFace.m_faceId  = face % 6;
		
		return loadFromImage(tmpFace.copyToImage());
	}
Exemplo n.º 6
0
static int engine_init_display(struct engine* engine) 
{
    // initialize OpenGL ES and EGL


    const EGLint attribs[] = 
    {
            EGL_NATIVE_VISUAL_ID, WINDOW_FORMAT_RGB_565,
            EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
    	    EGL_BLUE_SIZE, 5,
            EGL_GREEN_SIZE, 6,
            EGL_RED_SIZE, 5,
            EGL_DEPTH_SIZE,1,
            EGL_NONE
    };



    EGLint w, h, dummy, format;
    EGLint numConfigs;
    EGLConfig config;
    EGLSurface surface;
    EGLContext context;

    EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);


    EGLint majorVersion;
    EGLint minorVersion;

    eglInitialize(display, &majorVersion, &minorVersion);
    //eglInitialize(display, 0, 0);
    LOGI("OpenGL %i.%i", majorVersion,minorVersion);

    //query num of configs
    int* num_conf = new int[1];
    eglGetConfigs(display, NULL, 0, num_conf);  //if configuration array is null it still returns the number of configurations
    int configurations = num_conf[0];

    LOGI("total num configs: %i", configurations);

    //just some debugging info if the need arises...
    LOGI("EGL_OPENGL_ES2_BIT id:%i", EGL_OPENGL_ES2_BIT); //print the numerical code for the ES2 bit mask, etc
    LOGI("EGL_SURFACE_TYPE::EGL_WINDOW_BIT id:%i", EGL_WINDOW_BIT);
    LOGI("WINDOW_FORMAT_RGB_565 id:%i", WINDOW_FORMAT_RGB_565);

    //now query the configs
    EGLConfig* conf = new EGLConfig[configurations];
    eglGetConfigs(display, conf, configurations, num_conf);

    int* depth = new int[1];
	int* r = new int[1];
	int* g = new int[1];
	int* b = new int[1];
	int* a = new int[1];
	int* s = new int[1];
	int* renderType = new int[1];
	int* surfaceType = new int[1];
	int* formatType = new int[1];

	EGLConfig configToUse; //this is the one true config that we will use

    for(int i = 0; i < configurations; i++)
     {
      eglGetConfigAttrib(display, conf[i], EGL_DEPTH_SIZE, depth);
      eglGetConfigAttrib(display, conf[i], EGL_RED_SIZE, r);
      eglGetConfigAttrib(display, conf[i], EGL_GREEN_SIZE, g);
      eglGetConfigAttrib(display, conf[i], EGL_BLUE_SIZE, b);
      eglGetConfigAttrib(display, conf[i], EGL_ALPHA_SIZE, a);
      eglGetConfigAttrib(display, conf[i], EGL_RENDERABLE_TYPE, renderType);
      eglGetConfigAttrib(display, conf[i], EGL_STENCIL_SIZE, s);
      eglGetConfigAttrib(display, conf[i], EGL_SURFACE_TYPE, surfaceType);
      eglGetConfigAttrib(display, conf[i], EGL_NATIVE_VISUAL_ID, formatType);

      LOGI("(R%i,G%i,B%i,A%i)depth:(%i) stencil:(%i) surfaceType:(%i) renderType:(%i) formatType:(%i)",r[0],g[0],b[0],a[0],depth[0],s[0],surfaceType[0], renderType[0],formatType[0]);


      if((renderType[0] & EGL_OPENGL_ES2_BIT) > 0 &&
    	(surfaceType[0] & EGL_WINDOW_BIT) > 0 &&
    	(formatType[0] & WINDOW_FORMAT_RGB_565) > 0 &&
    	depth[0]>0)
      {

    	  configToUse=conf[i];

    	  LOGI("Config #%i" , i );

    	  LOGI("(R%i,G%i,B%i,A%i) %idepth %istencil %isurfaceType %iNativeVisualId",r[0],g[0],b[0],a[0],depth[0],s[0],surfaceType[0],formatType[0]);
      }

     }

    //bridge the pixel format back into android
    eglGetConfigAttrib(display, configToUse, EGL_NATIVE_VISUAL_ID, &format);
    ANativeWindow_setBuffersGeometry(engine->app->window, 0, 0, format);

    surface = eglCreateWindowSurface(display, configToUse, engine->app->window, NULL);

    if(surface == EGL_NO_SURFACE ) 
    {
    	LOGW("Error making surface, EGL_NO_SURFACE");
    }

    //now create the OpenGL ES2 context
    const EGLint contextAttribs[] = 
    {
    		EGL_CONTEXT_CLIENT_VERSION , 2,
    		EGL_NONE
    };

    context = eglCreateContext(display, configToUse, NULL, contextAttribs);

    if(context == EGL_NO_CONTEXT ) 
    {
    	LOGW("Error making context, EGL_NO_CONTEXT");
    }

    if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) 
    {
        LOGW("Unable to eglMakeCurrent");
        return -1;
    }

    eglQuerySurface(display, surface, EGL_WIDTH, &w);
    eglQuerySurface(display, surface, EGL_HEIGHT, &h);


    ContextWidth = w;
    ContextHeight = h;

    engine->display = display;
    engine->context = context;
    engine->surface = surface;
    engine->width = w;
    engine->height = h;
    engine->state.angle = 0;

    glEnable(GL_CULL_FACE);
    glDisable(GL_DEPTH_TEST);

    //GLubyte* rendererString = new GLubyte[512];
    const GLubyte* rendererString = rendererString=glGetString(GL_VERSION);
    LOGI("Renderer: %s",rendererString);


    //
	//
	// LOAD ALL RESOURCES
	//
	//

    //////////////////
    // PHONG SHADER //
    //////////////////

    if(!PhongShader.createShader((char*)"phong.vs",(char*)"phong.fs"))
    {
    	LOGE("Could not create phong program.");
    	return false;
    }

	PositionAttributes = glGetAttribLocation(PhongShader.ID, "aPosition");
	NormalAttributes =   glGetAttribLocation(PhongShader.ID, "aNormal");
	TexCoordAttributes = glGetAttribLocation(PhongShader.ID, "aTexCoords");
	MVPMatrixUniform = glGetUniformLocation( PhongShader.ID, "MVPMatrixUniform" );
	EyePosUniform = glGetUniformLocation(PhongShader.ID,"EyePosUniform");
	LightPosUniform = glGetUniformLocation(PhongShader.ID,"LightPosUniform");
	TextureSampler = glGetUniformLocation(PhongShader.ID,"sTexture");

	LOGI("===PHONG-DEBUG VALUES===");
	LOGI("PositionAttributes: %i",PositionAttributes);
	LOGI("NormalAttributes: %i",NormalAttributes);
	LOGI("TexCoordAttributes: %i",TexCoordAttributes);

	LOGI("MVPMatrixUniform: %i",MVPMatrixUniform);
	LOGI("EyePosUniform: %i",EyePosUniform);
	LOGI("LightPosUniform: %i",LightPosUniform);

	LOGI("TextureSampler: %i",TextureSampler);
	LOGI("===END===");

    //////////////////
    // DEPTH SHADER //
    //////////////////

	if(!DepthShader.createShader((char*)"depthcolor.vs",(char*)"depthcolor.fs")) 
	{
		LOGE("Could not create depth shader program.");
		return false;
	}

	DepthShaderMVPMatrixUniform = 	glGetUniformLocation(DepthShader.ID, "MVPMatrixUniform");
	DepthShaderPositionAttributes = glGetAttribLocation(DepthShader.ID, "aPosition");

	LOGI("===DEPTH-DEBUG VALUES===");
	LOGI("DepthShaderPositionAttributes: %i",DepthShaderPositionAttributes);
	LOGI("DepthShaderMVPMatrixUniform: %i",DepthShaderMVPMatrixUniform);
	LOGI("===END===");
	/////////////////////////////////
	// TEXPASSTHRU (SKYBOX) SHADER //
	/////////////////////////////////

	if(!TexPassThruShader.createShader((char*)"texpassthru.vs",(char*)"texpassthru.fs")) 
	{
		LOGE("Could not create texpassthru program.");
		return false;
	}

	TexPassThruSampler = glGetUniformLocation(TexPassThruShader.ID,"sTexture");
	TexPassThruMVPMatrixUniform = glGetUniformLocation(TexPassThruShader.ID,"MVPMatrixUniform");

	TexPassThruPositionAttributes = glGetAttribLocation(TexPassThruShader.ID, "aPosition");
	TexPassThruTexCoordAttributes = glGetAttribLocation(TexPassThruShader.ID, "aTexCoords");

	LOGI("===TEXPASSTHRU-DEBUG VALUES===");
	LOGI("TexPassThruSampler: %i",TexPassThruSampler);
	LOGI("TexPassThruMVPMatrixUniform: %i",TexPassThruMVPMatrixUniform);
	LOGI("TexPassThruPositionAttributes: %i",TexPassThruPositionAttributes);
	LOGI("TexPassThruTexCoordAttributes: %i",TexPassThruTexCoordAttributes);
	LOGI("===END===");



    ////////////////////////
    // ENVIRONMENT SHADER //
    ////////////////////////

	if (!EnvironmentMappingShader.createShader((char*)"environmentcubemap.vs",(char*)"environmentcubemap.fs")) 
	{
		LOGE("Could not create program.");
		return false;
	}

	EnvironmentMappingShaderMVPMatrixUniform=glGetUniformLocation(EnvironmentMappingShader.ID,"MVPMatrixUniform");
	EnvironmentMappingShaderPositionAttributes=glGetAttribLocation(EnvironmentMappingShader.ID, "aPosition");
	EnvironmentMappingShaderNormalAttributes=glGetAttribLocation(EnvironmentMappingShader.ID, "aNormal");
	EnvironmentMappingShaderCubeSampler=glGetUniformLocation(EnvironmentMappingShader.ID,"sCubeTexture");

	LOGI("===ENVIRONMENT-DEBUG VALUES===");
	LOGI("EnvironmentMappingShaderCubeSampler: %i",EnvironmentMappingShaderCubeSampler);
	LOGI("EnvironmentMappingShaderMVPMatrixUniform: %i",EnvironmentMappingShaderMVPMatrixUniform);
	LOGI("EnvironmentMappingShaderPositionAttributes: %i",EnvironmentMappingShaderPositionAttributes);
	LOGI("TexPassThruTeEnvironmentMappingShaderNormalAttributesxCoordAttributes: %i",EnvironmentMappingShaderNormalAttributes);
	LOGI("===END===");

	//Matrices
	esMatrixLoadIdentity(&MVPMatrix);

	//viewport
	glViewport(0, 0, w, h);
	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	checkGlError("glViewport");

	//load resources internally from the APK

	StatueMesh.loadMesh((char*)"athena.obj");
	checkGlError("loadMesh");

	if(!StoneTexture.loadTexture((char*)"rockish.tga")) 
	{
		LOGE("texture loading FAILED");
	}

	CubeSkyBox.loadSkyBox();

	if(!EnvironmentCubeTexture.loadCubeTexture())
		LOGE("Could not load cube texture.");

    return 0;
}