コード例 #1
0
ファイル: main.cpp プロジェクト: prokura/bahamut-engine
void Game()
{
    bool running = Renderer_Init( 800, 600, "Bahamuto" );

	Texture_Create( "Data\\Image\\bahaAlpha.png" );
	Shader_Create("Data\\Shader\\texture.fx");

	while( running  && !Window_GetMessage() )
	{
		/*float delta_time = 1.0f/60.0f;*/
		// Run systems
		Renderer_Draw();		
	}
		
	Renderer_Terminate();
}
コード例 #2
0
ファイル: demo_5.c プロジェクト: master-g/kitsune
void demo5_onSurfaceCreated(void)
{
    int i = 0;
    const char *vShaderStr =
    "uniform float u_time;		                          \n"
    "uniform vec3 u_centerPosition;                       \n"
    "attribute float a_lifetime;                          \n"
    "attribute vec3 a_startPosition;                      \n"
    "attribute vec3 a_endPosition;                        \n"
    "varying float v_lifetime;                            \n"
    "void main()                                          \n"
    "{                                                    \n"
    "  if ( u_time <= a_lifetime )                        \n"
    "  {                                                  \n"
    "    gl_Position.xyz = a_startPosition +              \n"
    "                      (u_time * a_endPosition);      \n"
    "    gl_Position.xyz += u_centerPosition;             \n"
    "    gl_Position.w = 1.0;                             \n"
    "  }                                                  \n"
    "  else                                               \n"
    "     gl_Position = vec4( -1000, -1000, 0, 0 );       \n"
    "  v_lifetime = 1.0 - ( u_time / a_lifetime );        \n"
    "  v_lifetime = clamp ( v_lifetime, 0.0, 1.0 );       \n"
    "  gl_PointSize = ( v_lifetime * v_lifetime ) * 40.0; \n"
    "}                                                    \n";
    
    const char *fShaderStr =
    "precision mediump float;                             \n"
    "uniform vec4 u_color;		                          \n"
    "varying float v_lifetime;                            \n"
    "uniform sampler2D s_texture;                         \n"
    "void main()                                          \n"
    "{                                                    \n"
    "  vec4 texColor;                                     \n"
    "  texColor = texture2D( s_texture, gl_PointCoord );  \n"
    "  gl_FragColor = vec4( u_color ) * texColor;         \n"
    "  gl_FragColor.a *= v_lifetime;                      \n"
    "}                                                    \n";
    
    glClearColor(0.3f, 0.3f, 0.3f, 0.0f);
    
    memset(&context, 0, sizeof(demo5_ctx_t));
    
    context.shader = Shader_Create(&vShaderStr, &fShaderStr);
    shader_t *shader = context.shader;
    
    Shader_Link(shader);
    Shader_ValidateProgram(shader);
    
    context.lifetimeLoc = Shader_GetAttribLocation(shader, "a_lifetime");
    context.startPositionLoc = Shader_GetAttribLocation(shader, "a_startPosition");
    context.endPositionLoc = Shader_GetAttribLocation(shader, "a_endPosition");
    
    context.timeLoc = Shader_GetUniformLocation(shader, "u_time");
    context.centerPositionLoc = Shader_GetUniformLocation(shader, "u_centerPosition");
    context.colorLoc = Shader_GetUniformLocation(shader, "u_color");
    context.samplerLoc = Shader_GetUniformLocation(shader, "s_texture");
    
    Shader_Enable(shader);
    
    glClearColor(0.1f, 0.1f, 0.1f, 0.0f);
    
    srand((int)time(NULL));
    for (i = 0; i < NUM_PARTICLES; i++)
    {
        float *particleData = &context.particleData[i * PARTICLE_SIZE];
        
        /* lifetime of particle */
        (*particleData++) = ((float)(rand() % 10000) / 10000.0f);
        
        /* End position of particle */
        (*particleData++) = ((float)(rand() % 10000) / 5000.0f) - 1.0f;
        (*particleData++) = ((float)(rand() % 10000) / 5000.0f) - 1.0f;
        (*particleData++) = ((float)(rand() % 10000) / 5000.0f) - 1.0f;
        
        /* start position of particle */
        (*particleData++) = ((float)(rand() % 10000) / 40000.0f) - 0.125f;
        (*particleData++) = ((float)(rand() % 10000) / 40000.0f) - 0.125f;
        (*particleData++) = ((float)(rand() % 10000) / 40000.0f) - 0.125f;
    }
    
    context.time = 1.0f;
    context.textureID = demo5_loadTexture("lightmap.png");
}