CrtInt CrtRender::LoadCgProgram( CrtChar * fileName, const CrtInt programType ) { CrtChar fullFileName[CRT_MAX_NAME_SIZE]; sprintf(fullFileName, "%s%s", ShaderFilePrefix, fileName ); //CrtCpy( fullFileName, fileName ); CrtPrint("CrtRender::LoadCgProgram: Loading %s Shader From File \n", fileName ); // Load And Compile The Vertex Shader From File if ( programType == CrtFragmentProgram ) cgPrograms[NumCgPrograms] = cgCreateProgramFromFile(cgContext, CG_SOURCE, fullFileName, cgFragmentProfile, "main", 0); else cgPrograms[NumCgPrograms] = cgCreateProgramFromFile(cgContext, CG_SOURCE, fullFileName, cgVertexProfile, "main", 0); // Validate Success if (cgPrograms[NumCgPrograms] == NULL) { // Check for a Cg Error, If So switch to FixedFunction if ( ! CrtCheckForCgError() ) return -1; // failed to load CgShader CrtChar buff[100]; sprintf(buff,"CrtRender::LoadCgProgram: Failed Compile CgFile %s \n", fileName ); MessageBox(NULL, buff, "Cg Compile Error", MB_OK ); return -1; } cgGLLoadProgram(cgPrograms[NumCgPrograms]); NumCgPrograms ++; return NumCgPrograms - 1; }
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); }
static bool load_program( cg_shader_data_t *cg, unsigned idx, const char *prog, bool path_is_file) { bool ret = true; char *listing_f = NULL; char *listing_v = NULL; unsigned i, argc = 0; const char *argv[2 + GFX_MAX_SHADERS]; argv[argc++] = "-DPARAMETER_UNIFORM"; for (i = 0; i < GFX_MAX_SHADERS; i++) { if (*(cg->cg_alias_define[i])) argv[argc++] = cg->cg_alias_define[i]; } argv[argc] = NULL; if (path_is_file) { cg->prg[idx].fprg = cgCreateProgramFromFile(cg->cgCtx, CG_SOURCE, prog, cg->cgFProf, "main_fragment", argv); SET_LISTING(cg, f); cg->prg[idx].vprg = cgCreateProgramFromFile(cg->cgCtx, CG_SOURCE, prog, cg->cgVProf, "main_vertex", argv); SET_LISTING(cg, v); } else { cg->prg[idx].fprg = cgCreateProgram(cg->cgCtx, CG_SOURCE, prog, cg->cgFProf, "main_fragment", argv); SET_LISTING(cg, f); cg->prg[idx].vprg = cgCreateProgram(cg->cgCtx, CG_SOURCE, prog, cg->cgVProf, "main_vertex", argv); SET_LISTING(cg, v); } if (!cg->prg[idx].fprg || !cg->prg[idx].vprg) { RARCH_ERR("CG error: %s\n", cgGetErrorString(cgGetError())); if (listing_f) RARCH_ERR("Fragment:\n%s\n", listing_f); else if (listing_v) RARCH_ERR("Vertex:\n%s\n", listing_v); ret = false; goto end; } cgGLLoadProgram(cg->prg[idx].fprg); cgGLLoadProgram(cg->prg[idx].vprg); end: free(listing_f); free(listing_v); return ret; }
static bool d3d9_cg_load_program(void *data, void *fragment_data, void *vertex_data, const char *prog, bool path_is_file) { bool ret = true; const char *list = NULL; char *listing_f = NULL; char *listing_v = NULL; CGprogram *fPrg = (CGprogram*)fragment_data; CGprogram *vPrg = (CGprogram*)vertex_data; CGprofile vertex_profile = cgD3D9GetLatestVertexProfile(); CGprofile fragment_profile = cgD3D9GetLatestPixelProfile(); const char **fragment_opts = cgD3D9GetOptimalOptions(fragment_profile); const char **vertex_opts = cgD3D9GetOptimalOptions(vertex_profile); cg_renderchain_t *cg_data = (cg_renderchain_t*)data; RARCH_LOG("[D3D Cg]: Vertex profile: %s\n", cgGetProfileString(vertex_profile)); RARCH_LOG("[D3D Cg]: Fragment profile: %s\n", cgGetProfileString(fragment_profile)); if (path_is_file && !string_is_empty(prog)) *fPrg = cgCreateProgramFromFile(cg_data->cgCtx, CG_SOURCE, prog, fragment_profile, "main_fragment", fragment_opts); else *fPrg = cgCreateProgram(cg_data->cgCtx, CG_SOURCE, stock_cg_d3d9_program, fragment_profile, "main_fragment", fragment_opts); list = cgGetLastListing(cg_data->cgCtx); if (list) listing_f = strdup(list); if (path_is_file && !string_is_empty(prog)) *vPrg = cgCreateProgramFromFile(cg_data->cgCtx, CG_SOURCE, prog, vertex_profile, "main_vertex", vertex_opts); else *vPrg = cgCreateProgram(cg_data->cgCtx, CG_SOURCE, stock_cg_d3d9_program, vertex_profile, "main_vertex", vertex_opts); list = cgGetLastListing(cg_data->cgCtx); if (list) listing_v = strdup(list); if (!fPrg || !vPrg) { RARCH_ERR("CG error: %s\n", cgGetErrorString(cgGetError())); if (listing_f) RARCH_ERR("Fragment:\n%s\n", listing_f); else if (listing_v) RARCH_ERR("Vertex:\n%s\n", listing_v); ret = false; goto end; } cgD3D9LoadProgram(*fPrg, true, 0); cgD3D9LoadProgram(*vPrg, true, 0); end: free(listing_f); free(listing_v); return ret; }
static bool renderchain_compile_shaders(cg_renderchain_t *chain, void *fragment_data, void *vertex_data, const std::string &shader) { CGprogram *fPrg = (CGprogram*)fragment_data; CGprogram *vPrg = (CGprogram*)vertex_data; CGprofile vertex_profile = cgD3D9GetLatestVertexProfile(); CGprofile fragment_profile = cgD3D9GetLatestPixelProfile(); const char **fragment_opts = cgD3D9GetOptimalOptions(fragment_profile); const char **vertex_opts = cgD3D9GetOptimalOptions(vertex_profile); RARCH_LOG("[D3D Cg]: Vertex profile: %s\n", cgGetProfileString(vertex_profile)); RARCH_LOG("[D3D Cg]: Fragment profile: %s\n", cgGetProfileString(fragment_profile)); if (shader.length() > 0) { RARCH_LOG("[D3D Cg]: Compiling shader: %s.\n", shader.c_str()); *fPrg = cgCreateProgramFromFile(chain->cgCtx, CG_SOURCE, shader.c_str(), fragment_profile, "main_fragment", fragment_opts); if (cgGetLastListing(chain->cgCtx)) RARCH_ERR("[D3D Cg]: Fragment error:\n%s\n", cgGetLastListing(chain->cgCtx)); *vPrg = cgCreateProgramFromFile(chain->cgCtx, CG_SOURCE, shader.c_str(), vertex_profile, "main_vertex", vertex_opts); if (cgGetLastListing(chain->cgCtx)) RARCH_ERR("[D3D Cg]: Vertex error:\n%s\n", cgGetLastListing(chain->cgCtx)); } else { RARCH_LOG("[D3D Cg]: Compiling stock shader.\n"); *fPrg = cgCreateProgram(chain->cgCtx, CG_SOURCE, stock_program, fragment_profile, "main_fragment", fragment_opts); if (cgGetLastListing(chain->cgCtx)) RARCH_ERR("[D3D Cg]: Fragment error:\n%s\n", cgGetLastListing(chain->cgCtx)); *vPrg = cgCreateProgram(chain->cgCtx, CG_SOURCE, stock_program, vertex_profile, "main_vertex", vertex_opts); if (cgGetLastListing(chain->cgCtx)) RARCH_ERR("[D3D Cg]: Vertex error:\n%s\n", cgGetLastListing(chain->cgCtx)); } if (!fPrg || !vPrg) return false; cgD3D9LoadProgram(*fPrg, true, 0); cgD3D9LoadProgram(*vPrg, true, 0); return true; }
bool RenderChain::compile_shaders(CGprogram &fPrg, CGprogram &vPrg, const std::string &shader) { #ifdef HAVE_CG CGprofile vertex_profile = cgD3D9GetLatestVertexProfile(); CGprofile fragment_profile = cgD3D9GetLatestPixelProfile(); RARCH_LOG("[D3D Cg]: Vertex profile: %s\n", cgGetProfileString(vertex_profile)); RARCH_LOG("[D3D Cg]: Fragment profile: %s\n", cgGetProfileString(fragment_profile)); const char **fragment_opts = cgD3D9GetOptimalOptions(fragment_profile); const char **vertex_opts = cgD3D9GetOptimalOptions(vertex_profile); if (shader.length() > 0) { RARCH_LOG("[D3D Cg]: Compiling shader: %s.\n", shader.c_str()); fPrg = cgCreateProgramFromFile(cgCtx, CG_SOURCE, shader.c_str(), fragment_profile, "main_fragment", fragment_opts); if (cgGetLastListing(cgCtx)) RARCH_ERR("[D3D Cg]: Fragment error:\n%s\n", cgGetLastListing(cgCtx)); vPrg = cgCreateProgramFromFile(cgCtx, CG_SOURCE, shader.c_str(), vertex_profile, "main_vertex", vertex_opts); if (cgGetLastListing(cgCtx)) RARCH_ERR("[D3D Cg]: Vertex error:\n%s\n", cgGetLastListing(cgCtx)); } else { RARCH_LOG("[D3D Cg]: Compiling stock shader.\n"); fPrg = cgCreateProgram(cgCtx, CG_SOURCE, stock_program, fragment_profile, "main_fragment", fragment_opts); if (cgGetLastListing(cgCtx)) RARCH_ERR("[D3D Cg]: Fragment error:\n%s\n", cgGetLastListing(cgCtx)); vPrg = cgCreateProgram(cgCtx, CG_SOURCE, stock_program, vertex_profile, "main_vertex", vertex_opts); if (cgGetLastListing(cgCtx)) RARCH_ERR("[D3D Cg]: Vertex error:\n%s\n", cgGetLastListing(cgCtx)); } if (!fPrg || !vPrg) return false; cgD3D9LoadProgram(fPrg, true, 0); cgD3D9LoadProgram(vPrg, true, 0); #endif return true; }
CrtInt CrtRender::LoadCgProgram( CrtChar * fileName, const CrtInt programType ) { CrtChar fullFileName[CRT_MAX_NAME_SIZE]; CrtCpy( fullFileName, ShaderFilePrefix ); CrtCat( fullFileName, fileName ); CrtPrint(" Loading %s Shader From Binary \n", fullFileName ); // get the name extention CrtChar * ext = CrtGetExtention( fullFileName ); if ( !CrtCmpIn( ext, ".cg" ) && !CrtCmpIn( ext, ".CG" ) ) { CrtPrint("CrtRender::LoadCgProgram: Invalid File Name %s \n", fullFileName ); return -1; } // Load And Compile The Vertex Shader From File if ( programType == CrtFragmentProgram ) { CrtCpy( ext, ".cg" ); cgPrograms[NumCgPrograms] = cgCreateProgramFromFile(cgContext, CG_SOURCE, fullFileName, cgFragmentProfile, NULL, NULL); } else { CrtCpy( ext, ".cg" ); cgPrograms[NumCgPrograms] = cgCreateProgramFromFile(cgContext, CG_SOURCE, fullFileName, cgVertexProfile, "main", 0); } // Validate Success if (cgPrograms[NumCgPrograms] == NULL) { // Check for a Cg Error, If So switch to FixedFunction if ( ! CrtCheckForCgError() ) return -1; // failed to load CgShader CrtChar buff[CRT_MAX_NAME_SIZE]; sprintf(buff," Shader Load Failed %s \n", fileName ); return -1; } CrtPrint(" Shader ID %d \n", cgPrograms[NumCgPrograms] ); cgGLLoadProgram(cgPrograms[NumCgPrograms]); NumCgPrograms ++; return NumCgPrograms - 1; }
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); }
//##ModelId=4C32C8AB0148 void fluid::glExtension::btGLShaderModel_4_0::createGeometryShader(const char* path, const char* entry,btGLBufferBundle *bundle) { if(hasGeometry) cgDestroyProgram(geometryShader); if(path == NULL) hasGeometry=false; geometryShader=cgCreateProgramFromFile(context,CG_SOURCE,path,getProfile(CG_GL_GEOMETRY),entry,NULL); if(bundle != NULL) { //search for bindable uniform GLint max; glGetIntegerv(GL_MAX_VERTEX_BINDABLE_UNIFORMS_EXT,&max); char uniformBufferName[256]; for(int i=0;i < max;i++) { sprintf_s(uniformBufferName,256,"geometry_bindable_uniform_%d",i); if(bundle->existsName(uniformBufferName)) { CGbuffer buf=bundle->getBindableUniformBufferIdForName(uniformBufferName); cgSetProgramBuffer(geometryShader,i,buf); } } } cgGLLoadProgram(geometryShader); hasGeometry=true; }
void newScenes(int sc1, int sc2) { sprintf(fileName, "cg_%d_%d.txt", sc1, sc2); fileName[10] = '\0'; if((pts = fopen(fileName, "r")) == NULL){ printf("Couldn't open file: %s\n", fileName); exit(EXIT_FAILURE); } char *ln; size_t sz; posLen = 0; while((ln = fgetln(pts, &sz)) != NULL) { fillPoint(&(posList[posLen]), ln); posLen++; } fclose(pts); sprintf(progName, "cg_%d_%d.cg", sc1, sc2); cgGLUnbindProgram(f_prof); cgGLEnableProfile(f_prof); gen = cgCreateProgramFromFile(context, CG_SOURCE, progName, f_prof, "main", NULL); cgGLLoadProgram(gen); cgGLBindProgram(gen); cgGLEnableProfile(f_prof); }
// CreateVertexShaderFromFile Shader* RendererGL::CreateVertexShaderFromFile(const char* VertexFileName, const char* VertexMain, ShaderVersion eVVersion) { CGprogram CgVertexProgram = cgCreateProgramFromFile ( m_CgContext, /* Cg runtime context */ CG_SOURCE, /* Program in human-readable form */ VertexFileName, /* Name of file containing program */ m_CgVertexProfile, /* Profile: OpenGL ARB vertex program */ VertexMain, /* Entry function name */ NULL ); /* No extra compiler options */ checkForCgError("creating vertex program from string"); if (!CgVertexProgram) return NULL; cgGLLoadProgram(CgVertexProgram); checkForCgError("loading vertex program"); Shader *shader = KGE_NEW(ShaderGL)(CgVertexProgram, 0, NULL, NULL); return shader; }
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 }
static CGprogram LoadShaderFromSource(CGcontext cgtx, CGprofile target, const char* filename, const char *entry) { const char* args[] = { "-fastmath", "-unroll=all", "-ifcvt=all", 0 }; CGprogram id = cgCreateProgramFromFile(cgtx, CG_SOURCE, filename, target, entry, NULL); cgGLLoadProgram(id); return id; }
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; }
CGprogram LoadShaderFromSource(CGcontext cgtx, CGprofile target, const char* filename, const char* entry) { CGprogram id = cgCreateProgramFromFile(cgtx, CG_SOURCE, filename, target, entry, NULL); if(!id) { LOG_DBG("Failed to load shader program >>%s<< \nExiting\n", filename); CheckCgError(__LINE__); } return id; }
static bool load_program(unsigned index, const char *prog, bool path_is_file) { bool ret = true; char *listing_f = NULL; char *listing_v = NULL; if (path_is_file) { prg[index].fprg = cgCreateProgramFromFile(cgCtx, CG_SOURCE, prog, cgFProf, "main_fragment", cg_arguments); SET_LISTING(f); prg[index].vprg = cgCreateProgramFromFile(cgCtx, CG_SOURCE, prog, cgVProf, "main_vertex", cg_arguments); SET_LISTING(v); } else { prg[index].fprg = cgCreateProgram(cgCtx, CG_SOURCE, prog, cgFProf, "main_fragment", cg_arguments); SET_LISTING(f); prg[index].vprg = cgCreateProgram(cgCtx, CG_SOURCE, prog, cgVProf, "main_vertex", cg_arguments); SET_LISTING(v); } if (!prg[index].fprg || !prg[index].vprg) { RARCH_ERR("CG error: %s\n", cgGetErrorString(cgGetError())); if (listing_f) RARCH_ERR("Fragment:\n%s\n", listing_f); else if (listing_v) RARCH_ERR("Vertex:\n%s\n", listing_v); ret = false; goto end; } cgGLLoadProgram(prg[index].fprg); cgGLLoadProgram(prg[index].vprg); end: free(listing_f); free(listing_v); return ret; }
void VertexObject::CreateProgram(const char* fileName, const char* functionName) { vertexProgram = cgCreateProgramFromFile( OpenGLRenderer::GetContext(), CG_SOURCE, fileName, //File name of shader program OpenGLRenderer::GetVertexProfile(), functionName, //Entry function NULL); OpenGLRenderer::checkForCgError("Creating vertex program from file"); }
void CGShader::init(const char *filename, const char *funcname, const char **options) { char* gpopt[3]={0,"-profileopts Vertices=16",0}; assert(cgIsContext(*m_pCgContext)); //if (*m_pCGProfile == cgGLGetLatestProfile(CG_GL_GEOMETRY)){ // options = &gpopt[0]; //} m_program = cgCreateProgramFromFile(*m_pCgContext, CG_SOURCE, filename, *m_pCGProfile, funcname, (const char**)gpopt); if (!cgIsProgramCompiled(m_program)) cgCompileProgram(m_program); cgGLLoadProgram(m_program); }
void Sum::init_cg() { cgProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT) ; cgContext = cgCreateContext(); errContext = cgContext; cgSetErrorCallback(cgErrorCallbackSum); fragmentProgram4tap = cgCreateProgramFromFile( cgContext, CG_SOURCE, "FP-4tap.cg", cgProfile, "FragmentProgram", 0); fragmentProgram8tap= cgCreateProgramFromFile( cgContext, CG_SOURCE, "FP-8tap.cg", cgProfile, "FragmentProgram", 0); fragmentProgram8tapY= cgCreateProgramFromFile( cgContext, CG_SOURCE, "FP-8tapY.cg", cgProfile, "FragmentProgram", 0); cgGLLoadProgram( fragmentProgram4tap ); cgGLLoadProgram( fragmentProgram8tap ); cgGLLoadProgram( fragmentProgram8tapY); }
void cgtk::load_fragment_program(CGprogram &f_program,char *shader_path, char *program_name) { assert(cgIsContext(context)); f_program = cgCreateProgramFromFile(context, CG_SOURCE, shader_path, fragmentProfile,program_name, NULL); if (!cgIsProgramCompiled(f_program)) cgCompileProgram(f_program); cgGLEnableProfile(fragmentProfile); cgGLLoadProgram(f_program); cgGLDisableProfile(fragmentProfile); }
void cgtk::load_vertex_program(CGprogram &v_program,char *shader_path, char *program_name) { assert(cgIsContext(context)); v_program = cgCreateProgramFromFile(context, CG_SOURCE,shader_path, vertexProfile,program_name, NULL); if (!cgIsProgramCompiled(v_program)) cgCompileProgram(v_program); cgGLEnableProfile(vertexProfile); cgGLLoadProgram(v_program); cgGLDisableProfile(vertexProfile); }
Shader::Shader(std::string shader_name) { // Be carefull: Cg needs a valid OpenGL context (be sure no shader is created before we have an OpenGL window) if (!cg_context) { cg_context = cgCreateContext(); vertex_profile = cgGLGetLatestProfile(CG_GL_VERTEX); // auto-detect best vertex profile cgGLSetOptimalOptions(vertex_profile); fragment_profile = cgGLGetLatestProfile(CG_GL_FRAGMENT); // auto-detect best fragment profile cgGLSetOptimalOptions(fragment_profile); } if (shader_name.length()) { vertex_program = cgCreateProgramFromFile(cg_context, CG_SOURCE, shader_name.c_str(), vertex_profile, "VertexProgram", 0); CGerror vertex_error = cgGetError(); if (vertex_error != CG_NO_ERROR) { printf("Warning: No valid vertex program found in %s: %s\n", shader_name.c_str(), cgGetErrorString(vertex_error)); vertex_program = 0; } else { cgGLLoadProgram(vertex_program); } fragment_program = cgCreateProgramFromFile(cg_context, CG_SOURCE, shader_name.c_str(), fragment_profile, "FragmentProgram", 0); CGerror fragment_error = cgGetError(); if (fragment_error != CG_NO_ERROR) { printf("Warning: No valid fragment program found in %s: %s\n", shader_name.c_str(), cgGetErrorString(fragment_error)); fragment_program = 0; } else { cgGLLoadProgram(fragment_program); } } }
bool Glow::LoadProgram(CGprogram* pDest, CGprofile profile, const char* szFile) { char file[512]; sprintf_s(file, "%s", szFile); *pDest = cgCreateProgramFromFile(this->g_cgContext, CG_SOURCE, file, profile, "main", 0); if (!(*pDest)) { MessageBox(NULL, cgGetErrorString(cgGetError()), NULL, NULL); return false; } cgGLLoadProgram(*pDest); return true; }
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; }
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" ); } }
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; }
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; }
//START shader glow effect -- FragBait0 inline bool LoadProgram(CGprogram* pDest, CGprofile profile, const char* szFile) { const char* szGameDir = gEngfuncs.pfnGetGameDirectory(); char file[512]; sprintf(file, "%s/%s", szGameDir, szFile); *pDest = cgCreateProgramFromFile(g_cgContext, CG_SOURCE, file, profile, "main", 0); if (!(*pDest)) { #ifdef _WIN32 MessageBox(NULL, cgGetErrorString(cgGetError()), NULL, NULL); #else SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "CG", cgGetErrorString(cgGetError()), NULL); #endif return false; } cgGLLoadProgram(*pDest); return true; }
Shader::Shader(ShaderSystem *shaderContext,const char *filename, const char *entryPoint,int shaderType) { CGprofile profile; if(NULL==shaderContext) systemError("invalid shader context"); context=shaderContext; if(VERTEX==shaderType) { profile=shaderContext->vertexProfile; } else if(FRAGMENT==shaderType) { profile=shaderContext->fragmentProfile; } else systemError("invalid shader type"); program=cgCreateProgramFromFile(shaderContext->cgContext,CG_SOURCE,filename,profile,entryPoint,NULL); context->checkError("creating shader program from file"); cgGLLoadProgram(program); context->checkError("loading shader program"); }
void FreezeParticle::InitializeFreezeParticleShader() { TextureLoader textureLoader; glTexture FreezeParticleTexture; FreezeParticleProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT); cgGLSetOptimalOptions(FreezeParticleProfile); CheckForCgError("FreezeParticle", "selecting fragment profile"); FreezeParticleProgram = cgCreateProgramFromFile(ShaderContext, CG_SOURCE, "assets/pixelshaders/ps_freezeparticle.cg", FreezeParticleProfile, "pixelMain", 0); CheckForCgError("FreezeParticle", "creating fragment program from file"); cgGLLoadProgram(FreezeParticleProgram); CheckForCgError("FreezeParticle", "loading fragment program"); FreezeParticleCoord0 = cgGetNamedParameter(FreezeParticleProgram, "texcoord0"); textureLoader.LoadTextureFromDisk("assets/textures/weapon/freezeparticle.tga", &FreezeParticleTexture); FreezeParticleText1 = cgGetNamedParameter(FreezeParticleProgram, "text1"); cgGLSetTextureParameter(FreezeParticleText1, FreezeParticleTexture.TextureID); CheckForCgError("FreezeParticle", "setting decal 2D texture"); }