Beispiel #1
0
static bool d3d_init_shader(void *data)
{
   d3d_video_t *d3d = (d3d_video_t*)data;
   (void)d3d;
	(void)data;
#if defined(HAVE_HLSL)
   RARCH_LOG("D3D]: Using HLSL shader backend.\n");
   const shader_backend_t *backend = &hlsl_backend;
   const char *shader_path = g_settings.video.shader_path;
   d3d->shader = backend;
   if (!d3d->shader)
      return false;

   return d3d->shader->init(d3d, shader_path);
#elif defined(HAVE_CG)
   d3d->cgCtx = cgCreateContext();
   if (!d3d->cgCtx)
      return false;

   RARCH_LOG("[D3D]: Created shader context.\n");

   HRESULT ret = cgD3D9SetDevice(d3d->dev);
   if (FAILED(ret))
      return false;
   return true;
#elif defined(_XBOX1)
	return false;
#endif
}
void ParticleShaderDiskDevelop::setupCG()
{

	if (cgGLIsProfileSupported(CG_PROFILE_VP30))
		vProfile = CG_PROFILE_VP30;
	else exit(-1);

	if (cgGLIsProfileSupported(CG_PROFILE_FP30))
		fProfile = CG_PROFILE_FP30;
	else exit(-1);

	// Create the Cg context
	CGcontext cgContext = cgCreateContext();
	
	// Create the vertex program
	vProgram = cgCreateProgramFromFile(cgContext, CG_SOURCE, "../Particles/vertex.cg", 
		vProfile, NULL, NULL);
	cgGLLoadProgram(vProgram);

	// Create the fragment programs
	fProgram = cgCreateProgramFromFile(cgContext, CG_SOURCE, "../Particles/clip_frag_d.cg",
		fProfile, NULL, NULL);
	cgGLLoadProgram(fProgram);

}
Beispiel #3
0
ShaderSystem::ShaderSystem()
{
	cgContext=cgCreateContext();
	checkError("creating context");
	cgGLSetDebugMode(CG_FALSE);
	cgSetParameterSettingMode(cgContext,CG_DEFERRED_PARAMETER_SETTING);

	//profiles
	vertexProfile=cgGLGetLatestProfile(CG_GL_VERTEX);
	cgGLSetOptimalOptions(vertexProfile);
	checkError("selecting vertex profile");

	fragmentProfile=cgGLGetLatestProfile(CG_GL_FRAGMENT);
	cgGLSetOptimalOptions(fragmentProfile);
	checkError("selecting fragment profile");

	printf("vertex profile:   %s\n",
		cgGetProfileString(cgGLGetLatestProfile(CG_GL_VERTEX)));
	printf("geometry profile: %s\n",
		cgGetProfileString(cgGLGetLatestProfile(CG_GL_GEOMETRY)));
	printf("fragment profile: %s\n",
		cgGetProfileString(cgGLGetLatestProfile(CG_GL_FRAGMENT)));



}
Beispiel #4
0
INT WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
	g_cgContext = cgCreateContext();
	checkForCgError("creating context");
	cgSetParameterSettingMode(g_cgContext, CG_DEFERRED_PARAMETER_SETTING);

	DXUTSetCallbackDeviceReset(OnResetDevice);
	DXUTSetCallbackDeviceLost(OnLostDevice);
	DXUTSetCallbackFrameRender(OnFrameRender);

	/* Parse  command line, handle  default hotkeys, and show messages. */
	DXUTInit();

	DXUTCreateWindow(g_strWindowTitleW);

	/* Display 400x400 window. */
	DXUTCreateDevice(D3DADAPTER_DEFAULT, true, 400, 400);

	DXUTMainLoop();

	cgDestroyProgram(g_cgVertexProgram);
	checkForCgError("destroying vertex program");
	cgDestroyContext(g_cgContext);

	return DXUTGetExitCode();
}
 //-----------------------------------------------------------------------
 CgProgramFactory::CgProgramFactory()
 {
     mCgContext = cgCreateContext();
     // Check for errors
     checkForCgError("CgProgramFactory::CgProgramFactory", 
         "Unable to create initial Cg context: ", mCgContext);
 }
Beispiel #6
0
/**
 * @fn Initialize()
 * @brief Setup the simulation.
 */ 
void Initialize()
{
  // Initialize the UI
  InitParameters();
  
  // First initialize extensions.
  int err = glewInit();

  if (GLEW_OK != err)
  {
    /* problem: glewInit failed, something is seriously wrong */
    fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
    exit(-1);
  }

  // Create the Cg context
  cgSetErrorCallback(cgErrorCallback);

  // Create cgContext.
  g_cgContext = cgCreateContext();
  
  // Create and initialize the Flo simulator object
  g_pFlo = new Flo(g_iFloWidth, g_iFloHeight);
  g_pFlo->Initialize(g_cgContext);

  glDisable(GL_DEPTH_TEST);
  glDisable(GL_LIGHTING);
}
Beispiel #7
0
    CgDxEffect::CgDxEffect(D3D11GraphicDevice* device):
        mContext(0),
        mDevice(device) {
            mContext = cgCreateContext();
            mist_assert(mContext);

            cgD3D11SetDevice(mContext, device->getD3DDevice());
    }
Beispiel #8
0
CShaderLoader::CShaderLoader(TShaderType type) :
ILoader  (),
m_type   (type),
m_shader (nullptr)
{
    // Création du context
    m_context = cgCreateContext();
}
Beispiel #9
0
/*-------------------------------------------------------------------------

  -------------------------------------------------------------------------*/
bool FilterBox::Initialize(int w, int h)
{
  bufw = w;
  bufh = h;
  //
  // FBO
  //
  glGenFramebuffersEXT(2, fb);
  glGenTextures(2, textureID);
  glGenRenderbuffersEXT(1, &depth_rb);
  initRT(0, w, h);
  initRT(1, w, h);
  //
  // initialize depth renderbuffer
  //
  glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depth_rb);
  glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, w, h);
  glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, 
                                GL_RENDERBUFFER_EXT, depth_rb);
  CheckFramebufferStatus();

  glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
  //
  // CGFX things
  //
  cgContext = cgCreateContext();
  cgGLRegisterStates(cgContext);
  std::string resolved_path;

        cgEffect = cgCreateEffectFromFile(cgContext, "data/shaders/FilterBox.cgfx", NULL);
        if(!cgEffect)
        {
			exit(0);
            const char * pszErrors = NULL;
            fprintf(stderr, "CgFx Parse error : %s", pszErrors);
            const char *listing = cgGetLastListing(cgContext);
            bValid = false;
            return false;
        }
  cgTechnique = cgGetNamedTechnique(cgEffect, "Filter");
  cgPassFilterH = cgGetNamedPass(cgTechnique, "verticalPass");
  cgPassFilterV = cgGetNamedPass(cgTechnique, "horizontalPass");
  cgPassBlend   = cgGetNamedPass(cgTechnique, "drawFinal");
  cgBlendFactor = cgGetNamedEffectParameter(cgEffect, "blendFactor");
  cgGlowFactor  = cgGetNamedEffectParameter(cgEffect, "glowFactor");
  srcSampler    = cgGetNamedEffectParameter(cgEffect, "srcSampler");
  tempSampler   = cgGetNamedEffectParameter(cgEffect, "tempSampler");
  finalSampler  = cgGetNamedEffectParameter(cgEffect, "finalSampler");
  verticalDir   = cgGetNamedEffectParameter(cgEffect, "verticalDir");
  horizontalDir = cgGetNamedEffectParameter(cgEffect, "horizontalDir");

  cgGLSetParameter2f(verticalDir, 0,1.0f/(float)h);
  cgGLSetParameter2f(horizontalDir, 1.0f/(float)w, 0);

  bValid = true;
  return true;
}
Beispiel #10
0
void
CGlutCgWindow::initializeCg() {

	// Basic Cg setup; register a callback function for any errors
    // and create an initial context
    cgSetErrorCallback(handleCgError);
    s_CgContext = cgCreateContext();

}
Beispiel #11
0
    CgDxEffect::CgDxEffect(D3D11GraphicDevice* device):
        mContext(0),
        mDevice(device) {
            mContext = cgCreateContext();
            mist_assert(mContext);

            cgD3D11SetDevice(mContext, device->getD3DDevice());
            cgD3D11SetManageTextureParameters(mContext, CG_TRUE);
    }
Beispiel #12
0
int main( int argc, char **argv )
{
    glutInit( &argc, argv );
    glutInitWindowSize(1000, 1000);
    glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
    glutCreateWindow("Fractal Shader");
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutMotionFunc(mouseMove);
    glutMouseFunc(mouseAction);
    glutIdleFunc(OnIdle);
    glutKeyboardFunc(keyAction);
    glutKeyboardUpFunc(keyUp);
    glClearColor(0, 0, 0, 1);
    CGcontext context = cgCreateContext();
    if(context == NULL){
        printf("Failed to create CGcontext\n");
        return 1;
    }
	f_prof = cgGLGetLatestProfile(CG_GL_FRAGMENT); 
	v_prof = cgGLGetLatestProfile(CG_GL_VERTEX);
	printf("%d, %d\n", f_prof, v_prof);
    chdir("/Users/peter/Desktop/CG/cgtest");
    julia = cgCreateProgramFromFile(context, CG_SOURCE, "Julia.cg", f_prof, "main", NULL);
    newton = cgCreateProgramFromFile(context, CG_SOURCE, "Newton.cg", f_prof, "main", NULL);
    mandel = cgCreateProgramFromFile(context, CG_SOURCE, "Mandel.cg", f_prof, "main", NULL);
    ship = cgCreateProgramFromFile(context, CG_SOURCE, "Ship.cg", f_prof, "main", NULL);
    pass = cgCreateProgramFromFile(context, CG_SOURCE, "Pass.cg", v_prof, "main", NULL);
	gen = cgCreateProgramFromFile(context, CG_SOURCE, "GenIter.cg", f_prof, "main", NULL);
    printf("%s\n", cgGetErrorString(cgGetError()));
    cgGLLoadProgram(julia);
    cgGLLoadProgram(newton);
    cgGLLoadProgram(mandel);
    cgGLLoadProgram(ship);
	cgGLLoadProgram(gen);
    cgGLLoadProgram(pass);
    //printf("%s\n", cgGetErrorString(cgGetError()));
    cgGLEnableProfile(f_prof);
    cgGLEnableProfile(v_prof);
    printf("%s\n", cgGetErrorString(cgGetError()));
	
	Position demoList[7];
	fillPoint(&demoList[0], 0.297205, 0.063085, 0.001157, 1.012991, 15.0, 7);
	fillPoint(&demoList[1], 0.134370, 0.042840, 0.043976, 1.008928, 15.0, 7);
	fillPoint(&demoList[2], -0.129831, -0.637758, 0.507148, 1.103996, 15.0, 7);
	fillPoint(&demoList[3], -0.162030, -1.02009, 0.041826, 0.983991, 15.0, 7);
	fillPoint(&demoList[4], -0.139263, -1.846086, 0.002345, 0.516934, 15.0, 7);
	fillPoint(&demoList[5], -0.138215, -1.910406, 0.001638, 0.495934, 15.0, 7);
	fillPoint(&demoList[6], -0.138215, -3.552904, 0.302149, 0.149937, 15.0, 7);
	
	posList = demoList;
	zoom = 0.001157;
	
    glutMainLoop();
    return 0;
}
Beispiel #13
0
GPUProgram::GPUProgram(void)
{
    cgSetErrorCallback(handleCgError);
    context = cgCreateContext();
    if (!cgIsContext(context)){
		fprintf(stderr, "Cg Error: cannot create context!\n");
		exit(1);
	}
	_chooseProfiles();
}
Beispiel #14
0
bool ZZshStartUsingShaders() {
	cgSetErrorHandler(HandleCgError, NULL);
	g_cgcontext = cgCreateContext();

	cgvProf = CG_PROFILE_ARBVP1;
	cgfProf = CG_PROFILE_ARBFP1;
	cgGLEnableProfile(cgvProf);
	cgGLEnableProfile(cgfProf);
	cgGLSetOptimalOptions(cgvProf);
	cgGLSetOptimalOptions(cgfProf);

	cgGLSetManageTextureParameters(g_cgcontext, CG_FALSE);
	//cgSetAutoCompile(g_cgcontext, CG_COMPILE_IMMEDIATE);

	g_fparamFogColor = cgCreateParameter(g_cgcontext, CG_FLOAT4);
	g_vparamPosXY[0] = cgCreateParameter(g_cgcontext, CG_FLOAT4);
	g_vparamPosXY[1] = cgCreateParameter(g_cgcontext, CG_FLOAT4);


	ZZLog::GS_Log("Creating effects.");
	B_G(LoadEffects(), return false);

	// create a sample shader
	clampInfo temp;
	memset(&temp, 0, sizeof(temp));
	temp.wms = 3; temp.wmt = 3;

	g_nPixelShaderVer = 0;//SHADER_ACCURATE;
	// test
	bool bFailed;
	FRAGMENTSHADER* pfrag = ZZshLoadShadeEffect(0, 1, 1, 1, 1, temp, 0, &bFailed);
	if( bFailed || pfrag == NULL ) {
		g_nPixelShaderVer = SHADER_ACCURATE|SHADER_REDUCED;

		pfrag = ZZshLoadShadeEffect(0, 0, 1, 1, 0, temp, 0, &bFailed);
		if( pfrag != NULL )
			cgGLLoadProgram(pfrag->prog);
		if( bFailed || pfrag == NULL || cgGetError() != CG_NO_ERROR ) {
			g_nPixelShaderVer = SHADER_REDUCED;
			ZZLog::Error_Log("Basic shader test failed.");
		}
	}

	if (g_nPixelShaderVer & SHADER_REDUCED)
		conf.bilinear = 0;

	ZZLog::GS_Log("Creating extra effects.");
	B_G(ZZshLoadExtraEffects(), return false);

	ZZLog::GS_Log("using %s shaders\n", g_pShaders[g_nPixelShaderVer]);
	return true;
}
Beispiel #15
0
//##ModelId=4C32C6EF0290
fluid::glExtension::btGLShaderModel_4_0::btGLShaderModel_4_0(const char* name)
{
	context=cgCreateContext();
	
	hasVertex=
	hasGeometry=
	hasFragment=false;

	isBind=false;

	this->name=(char*)malloc(strlen(name)+1);
	memcpy(this->name,name,strlen(name)+1);
}
void init( unsigned int _width, unsigned int _height ) {
  window_width = _width;
  window_height = _height;
  glfwInit();
  glfwOpenWindowHint( GLFW_FSAA_SAMPLES, 8 );
  glfwOpenWindow( window_width, window_height, 8, 8, 8, 8, 16, 0, GLFW_WINDOW );
  glfwSetWindowSizeCallback( &resizeEvent );
  std::cout << glGetString( GL_VERSION ) << std::endl;
  glfwSwapInterval( 1 );
  
  GLenum err = glewInit();
  if (GLEW_OK != err)
  {
    std::cout << "Error: " << glewGetErrorString(err) << std::endl;
    throw -1;
  }
  
//  ilInit();
//  iluInit();
  
  chdir( BOOST_PP_STRINGIZE( RESOURCE_DIRECTORY ) );
  
  cgSetErrorCallback(&checkCgError);
  context = cgCreateContext();
  cgGLRegisterStates( context );
  quit_flag = false;
  cam_position[ 0 ] = 0.0f;
  cam_position[ 1 ] = 3.5f;
  cam_position[ 2 ] = 7.0f;
  cam_velocity[ 0 ] = 0.0f;
  cam_velocity[ 1 ] = 0.0f;
  cam_velocity[ 2 ] = 0.0f;
  cam_velocity[ 3 ] = 0.0f;
  cam_direction[ 0 ] = 0.0f;
  cam_direction[ 1 ] = 0.0f;
  cam_direction[ 2 ] = -1.0f;
  light_position = 0.0;
  light_velocity = 0.0;
  obj_position[ 0 ] = 0.0f;
  obj_position[ 1 ] = 0.0f;
  obj_velocity[ 0 ] = 0.0f;
  obj_velocity[ 1 ] = 0.0f;
  cam_moving_x = 0;
  cam_moving_y = 0;
  cam_moving_z = 0;
  cam_moving_dir = 0;
  lit_moving_x = 0;
  obj_moving_x = 0;
  obj_moving_y = 0;
  glfwSetKeyCallback( &keycb );
}
Beispiel #17
0
    void Effect::initialize()
    {
        context = cgCreateContext();

        if (context == 0)
        {
            throw std::runtime_error("Could not create context");
        }

        cgSetErrorHandler(CgErrorHandler, 0);

        cgGLRegisterStates(context);
        cgGLSetManageTextureParameters(context, true);
    }
Beispiel #18
0
void InitCG()
{

    if( cgGLIsProfileSupported(CG_PROFILE_ARBVP1) )
        g_CGprofile_vertex = CG_PROFILE_ARBVP1;
    else if( cgGLIsProfileSupported(CG_PROFILE_VP40) )
        g_CGprofile_vertex = CG_PROFILE_VP40;
    else
    {
		ShaderWater=false;
        return;
    }

	
	if( cgGLIsProfileSupported(CG_PROFILE_ARBFP1) )
        g_CGprofile_pixel = CG_PROFILE_ARBFP1;
    else if( cgGLIsProfileSupported(CG_PROFILE_FP30) )
        g_CGprofile_pixel = CG_PROFILE_FP30;
	else if( cgGLIsProfileSupported(CG_PROFILE_FP20) )
        g_CGprofile_pixel = CG_PROFILE_FP20;
    else
    {
		ShaderWater=false;
		return;
    }
	g_CGcontext = cgCreateContext();
	
	g_Sea_vertex = cgCreateProgramFromFile( g_CGcontext,
												CG_SOURCE,
												"Sea_vertex.cg",
												g_CGprofile_vertex,
												NULL,
												NULL );
	cgGLLoadProgram(g_Sea_vertex);
	CGerror GetCGerror=cgGetError();
	if(GetCGerror!=CG_NO_ERROR)
		MessageBox (HWND_DESKTOP, "vertex shader Error!", "Error", MB_OK | MB_ICONEXCLAMATION);
	g_Sea_pixel = cgCreateProgramFromFile( g_CGcontext,
												CG_SOURCE,
												"Sea_pixel.cg",
												g_CGprofile_pixel,
												NULL,
												NULL );

	cgGLLoadProgram(g_Sea_pixel);
	GetCGerror=cgGetError();
	if(GetCGerror!=CG_NO_ERROR)
		MessageBox (HWND_DESKTOP, "pixel shader Error!", "Error", MB_OK | MB_ICONEXCLAMATION);
} 
Beispiel #19
0
void CgInit(){
	CgCtxt = cgCreateContext();
	CgProg = cgCreateProgramFromFile( CgCtxt, CG_SOURCE, "shader.cg",
											CgProf, NULL, NULL );
	if( CgProg != NULL ){
		
		cgGLLoadProgram( CgProg );
		
		ModelViewProjParam = cgGetNamedParameter( CgProg, "ModelViewProj" );
		
		LightAngle = cgGetNamedParameter( CgProg, "LA" );
		
		LightY = cgGetNamedParameter( CgProg, "LY" );
	}
}
Beispiel #20
0
int32_t PS3Graphics::InitCg()
{
	cgRTCgcInit();

	_cgContext = cgCreateContext();
	if (_cgContext == NULL)
		return 1;
	if (strlen(_curFragmentShaderPath.c_str()) > 0)
		return LoadFragmentShader(_curFragmentShaderPath.c_str());
	else
	{
		_curFragmentShaderPath = DEFAULT_SHADER_FILE;
		return LoadFragmentShader(_curFragmentShaderPath.c_str());
	}
}
Beispiel #21
0
bool d3d_init_shader(void *data)
{
   D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
   d3d->cgCtx = cgCreateContext();
   if (d3d->cgCtx == NULL)
      return false;

   RARCH_LOG("[D3D9 Cg]: Created context.\n");

   HRESULT ret = cgD3D9SetDevice(d3d->dev);
   if (FAILED(ret))
      return false;

   return true;
}
	i32 CCGShaderSystem::Init(IRenderSystem* pRS)
	{
		UnloadLibraries();
		if( XST_FAILED( LoadLibraries() ) )
		{
			return XST_FAIL;
		}

		m_pRS = pRS;

		m_CGContext = cgCreateContext();
		CHECK_CG_ERR( "creating context", "" );

		return XST_OK;
	}
Beispiel #23
0
int _tmain(int argc, char ** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
    glutInitWindowSize(500, 500);
    glutCreateWindow("render_texture_3D");
    glutDisplayFunc(display);
    glutKeyboardFunc(key);
    glutMotionFunc(myMotion);
    glutPassiveMotionFunc(myPMotion);
    glutIdleFunc(idle);
    context = cgCreateContext();
    cgSetErrorCallback(cgErrorCallback);
    fluid=new Fluid3D(context,64,64,64,0.0025f,1,0.5);
    glutMainLoop();
}
Beispiel #24
0
void _initCgRuntime(ID3D11Device *dev)
{
	if(gCgContext == nullptr) {
		std::cout << "[CgRuntime] Initialize Cg-Runtime-Direct3D 11" << std::endl;
		//qDebug("[Cg] Initialize Cg");
		// register the error handler
		cgSetErrorHandler( &_cgErrorHandler, NULL);
		// create a new Cg Context
		gCgContext = cgCreateContext();

		
		HRESULT hr = cgD3D11SetDevice( gCgContext, dev);
	
		if( hr != S_OK )
			return;

		// Register the default state assignment for OpenGL
		//cgD3D11RegisterStates(gCgContext);
		// This will allow the Cg runtime to manage texture binding
		//cgD3D11SetManageTextureParameters(gCgContext, CG_TRUE);
		
		gCgVertexShaderProfile = cgD3D11GetLatestVertexProfile();
		if(gCgVertexShaderProfile == CG_PROFILE_UNKNOWN)
		{
			// ERROR
			std::cout << "[CgRuntime] Error: Could not get valid Vertex-Profile." << std::endl;
			return;
		}
		
		gCgGeometryShaderProfile = cgD3D11GetLatestGeometryProfile();
		if(gCgGeometryShaderProfile == CG_PROFILE_UNKNOWN)
		{
			// WARNING
			std::cout << "[CgRuntime] Warning: Could not get valid Geometry-Profile." << std::endl;
		}
		
		gCgFragmentShaderProfile = cgD3D11GetLatestPixelProfile();
		if(gCgFragmentShaderProfile == CG_PROFILE_UNKNOWN)
		{
			// ERROR
			std::cout << "[CgRuntime] Error: Could not get valid Fragment-Profile." << std::endl;
			return;
		}

		profileOpts = cgD3D11GetOptimalOptions(gCgVertexShaderProfile);
	}
}
int main(int argc,char** argv) {
    diff_seconds();
    srand(time(NULL));

    glutInit(&argc, argv);
    glutInitDisplayMode( GLUT_DEPTH | GLUT_DOUBLE |GLUT_RGB);
    glutInitWindowSize (900,600);
    glutInitWindowPosition (240, 40);
    glutCreateWindow ("E16 - Partikelsystem");

    glutKeyboardFunc(keyboard);

    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glEnable(GL_COLOR_MATERIAL);

    init();
    glutDisplayFunc(display);

    glutIdleFunc(idle);

    glEnable(GL_DEPTH_TEST);
    /********************************************/

    cg_context = cgCreateContext();
    checkForCgError("creating context");

    cg_vertex_profile = cgGLGetLatestProfile(CG_GL_VERTEX);
    cgGLSetOptimalOptions(cg_vertex_profile);
    checkForCgError("selecting vertex profile");

    cg_vertex_program = cgCreateProgramFromFile(cg_context, CG_SOURCE, "vertex.cg",
                        cg_vertex_profile, "more_complex_vertex_shader", NULL);

    checkForCgError("creating vertex program from file");
    cgGLLoadProgram(cg_vertex_program);
    checkForCgError("loading vertex program");
    /**************************************************/
    cg_parameter_vertex_velocity = cgGetNamedParameter(cg_vertex_program, "Texture0");
    cg_parameter_vertex_time = cgGetNamedParameter(cg_vertex_program, "Texture1");


    glutMainLoop();

    return 0;
}
static bool d3d9_cg_renderchain_init_shader(d3d9_video_t *d3d,
      cg_renderchain_t *renderchain)
{
   CGcontext cgCtx    = cgCreateContext();

   if (!cgCtx)
   {
      RARCH_ERR("Failed to create Cg context.\n");
      return false;
   }

   if (FAILED(cgD3D9SetDevice((IDirect3DDevice9*)d3d->dev)))
      return false;

   renderchain->cgCtx = cgCtx;
   return true;
}
int main(int argc, char **argv) {

  glutInitWindowSize(600, 600);
  glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
  glutInit(&argc, argv);

  glutCreateWindow("Per vertex lighting (Gouraud shading)");
  glutDisplayFunc(display);
  glutKeyboardFunc(keyboard);
  glutReshapeFunc(reshape);

  glClearColor(0.0, 0.0, 0.0, 1.0);

  cg_context = cgCreateContext();
  checkForCgError("creating context");

  cg_vertex_profile = cgGLGetLatestProfile(CG_GL_VERTEX);
  cgGLSetOptimalOptions(cg_vertex_profile);
  checkForCgError("selecting vertex profile");

  cg_vertex_program = cgCreateProgramFromFile(cg_context, CG_SOURCE, "E12_vertex.cg", 
						cg_vertex_profile, "per_vertex_lighting", NULL);                 

  checkForCgError("creating vertex program from file");
  cgGLLoadProgram(cg_vertex_program);
  checkForCgError("loading vertex program");

  
  GET_PARAM(modelview_proj);
  GET_PARAM(translation);
  GET_PARAM(ambient_light);
  GET_PARAM(light_color);
  GET_PARAM(light_position);
  GET_PARAM(camera_position);
  GET_PARAM(Ke);
  GET_PARAM(Ka);
  GET_PARAM(Kd);
  GET_PARAM(Ks);
  GET_PARAM(exponent);

  glEnable(GL_DEPTH_TEST);

  glutMainLoop();
  return 0;
}
Beispiel #28
0
bool ShaderCG::init(const char* file_v, const char* file_f)
{
#ifdef HAS_CG
  CGcontext context = cgCreateContext();

  profile_vertex = cgGLGetLatestProfile(CG_GL_VERTEX);;
  profile_fragment = cgGLGetLatestProfile(CG_GL_FRAGMENT);;

  cgGLSetOptimalOptions(profile_vertex);
  cgGLSetOptimalOptions(profile_fragment);

  program_vertex   = cgCreateProgramFromFile(context, CG_SOURCE, file_v, profile_vertex  , 0, 0);
  program_fragment = cgCreateProgramFromFile(context, CG_SOURCE, file_f, profile_fragment, 0, 0);

  if (!program_vertex || !program_fragment)
  {
    ErrorCheck();
    use_cg = false;
    printf("Shaders Disabled\n");
    return false;
  }

  g_modelViewProjMatrix = cgGetNamedParameter(program_vertex, "ModelViewProj");
  g_modelViewMatrix = cgGetNamedParameter(program_vertex, "ModelView");
  g_modelViewMatrixI = cgGetNamedParameter(program_vertex, "ModelViewI");
  g_modelViewMatrixIT = cgGetNamedParameter(program_vertex, "ModelViewIT");

  g_lightPosition = cgGetNamedParameter(program_vertex, "LightPos");
  g_lightDiffuse  = cgGetNamedParameter(program_fragment, "lightcolor");
  //g_lightAmbiente = cgGetNamedParameter(program_vertex, "LightAmbiente");
  //g_lightSpecular = cgGetNamedParameter(program_vertex, "LightSpecular");

  cgGLLoadProgram(program_vertex);
  cgGLLoadProgram(program_fragment);

  ErrorCheck();

  printf("Shaders Enabled\n");

  return true;
#else
  printf("Shaders Disabled\n");
  return false;
#endif // HAS_CG
}
Beispiel #29
0
GLCgShaderContext::GLCgShaderContext() :
	m_cgContext(0)
{
	m_cgContext = cgCreateContext();
	CheckForError("GLCgShaderContext creating the context");

	cgSetParameterSettingMode(m_cgContext, CG_DEFERRED_PARAMETER_SETTING);
	CheckForError("GLCgShaderContext setting parameter mode");

	#ifdef DEBUG
		cgGLSetDebugMode(CG_TRUE);
	#else
		cgGLSetDebugMode(CG_FALSE);
	#endif

	m_latestFragmentProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT);
	m_latestVertexProfile   = cgGLGetLatestProfile(CG_GL_VERTEX);
}
Beispiel #30
0
int createShader ( int n, std::string vname, std::string vfunc, std::string fname, std::string ffunc)
{
#if 0
	char vnbuf[200];
	char vfbuf[200];
	char fnbuf[200];
	char ffbuf[200];
	strcpy ( vnbuf, vname.c_str() );
	strcpy ( vfbuf, vfunc.c_str() );
	strcpy ( fnbuf, fname.c_str() );
	strcpy ( ffbuf, ffunc.c_str() );

	if ( cgContext == 0 ) {
		cgSetErrorCallback( cgErrorCallback );
		cgContext = cgCreateContext();
	}

	// Select profiles
	vert_profile = cgGLGetLatestProfile ( CG_GL_VERTEX );
	cgGLSetOptimalOptions( vert_profile );
	
	frag_profile = cgGLGetLatestProfile ( CG_GL_FRAGMENT );
	cgGLSetOptimalOptions( frag_profile );

	printf ( "Vertex profile:   %s\n", cgGetProfileString(vert_profile) );
	printf ( "Fragment profile: %s\n", cgGetProfileString(frag_profile) );
	printf ( " (See http.developer.nvidia.com/Cg/index_profiles.html)\n");

	//debug.PrintF ( "rend", "Geometry profile: %s\n", cgGetProfileString(vert_profile) );	

	printf ( "Loading VP:       %s\n", vnbuf );
	cgVP = cgCreateProgramFromFile( cgContext, CG_SOURCE, vnbuf, vert_profile, vfbuf, NULL );
	cgGLLoadProgram( cgVP );
	
	printf ( "Loading FP:       %s\n", fnbuf );
	cgFP = cgCreateProgramFromFile( cgContext, CG_SOURCE, fnbuf, frag_profile, ffbuf, NULL );	
	cgGLLoadProgram( cgFP );
	
	cgGLSetManageTextureParameters ( cgContext, CG_FALSE ); 
	cgGLBindProgram ( cgVP );
	cgGLBindProgram ( cgFP );	
#endif
	return 0;
}