Exemplo n.º 1
0
void intro_do( long time )
{
    //--- update parameters -----------------------------------------

    const float t  = 0.001f*(float)time;

    // camera position
    fparams[ 0] = 2.0f;
    fparams[ 1] = 0.0f;
    fparams[ 2] = 2.0f; 
    // camera target
    fparams[ 4] = 0.0f;
    fparams[ 5] = 0.0f;
    fparams[ 6] = 0.0f;
    // sphere
    fparams[ 8] = 0.0f;
    fparams[ 9] = 0.0f;
    fparams[10] = 0.0f;
    fparams[11] = 1.0f;
	/*
	// Gen renderbuffer
	glGenRenderbuffersEXT(1, &frontb);

	// Bind renderbuffer
	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, frontb);

	// Init as a depth buffer
	glRenderbufferStorageEXT( GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, XRES, YRES);

	// Attach to the FBO for depth
	glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, frontb); 

	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 
	
	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);*/


    //--- render -----------------------------------------
	static float reso[4];
	reso[0] = XRES;
	reso[1] = YRES;
	reso[2] = XRES;
	reso[3] = YRES;
    oglUseProgram( pid );
	glUniform1fARB( oglGetUniformLocation( pid, "iGlobalTime" ),  t );
    oglUniform4fv( oglGetUniformLocation( pid, "iResolution" ),  1, reso );
    oglUniform4fv( oglGetUniformLocation( pid, "fpar" ),  4, fparams );
    glRects( -1, -1, 1, 1 );
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 
	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
}
Exemplo n.º 2
0
void Attribute::bindAsUniform( int index )
{
	switch( numComponents() )
	{
	case 1:
		if( elementComponentType() == GL_FLOAT )
		{
			//printf("setting uniform tmp: %f at uniform location %i\n", *((float *)getRawPointer()), index );
			oglUniform1fv( index, numElements(), (float *)getRawPointer());
		}
		else if( elementComponentType() == GL_INT )
		{
			oglUniform1iv( index, numElements(), (int*)getRawPointer());
		}else if( elementComponentType() == ATTR_TYPE_SAMPLER )
		{
			// get gl textureid
			unsigned int t = (unsigned int) (*(int*)getRawPointer());

			// bind texture to given texture unit (index)
			oglActiveTexture(GL_TEXTURE0+index);
			glBindTexture(GL_TEXTURE_2D, t);

			// now set the sampler uniform to point to the textureunit
			int tt = index; // for now texture unit == unfiform location
							// this will be bad with higher number of uniforms in shader
							// need more clever texture unit management
			oglUniform1iv( index, 1, &tt);
		}
		break;
	case 2:
		if( elementComponentType() == GL_FLOAT )
			oglUniform2fv( index, numElements(), (float *)getRawPointer());
		break;
	case 3:
		if( elementComponentType() == GL_FLOAT )
			oglUniform3fv( index, numElements(), (float *)getRawPointer());
		break;
	case 4:
		if( elementComponentType() == GL_FLOAT )
			oglUniform4fv( index, numElements(), (float *)getRawPointer());
		break;
	case 9:
		oglUniformMatrix3fv( index, numElements(), false, (float *)getRawPointer() );
		break;
	case 16:
		oglUniformMatrix4fv( index, numElements(), false, (float *)getRawPointer() );
		break;
	};
}