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))); }
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); }
// // AddRef // void CCgContext::AddRef() { if (m_RefCount == 0) { m_Context = cgCreateContext(); if (!m_Context) { CGerror Error = cgGetError(); if (Error != CG_NO_ERROR) throw CCgException( "GL::CCgContext", Error, "::AddRef() : Failed to create Cg context." ); } #ifdef _DEBUG cgGLSetDebugMode( CG_TRUE ); #else cgGLSetDebugMode( CG_FALSE ); #endif // Prevent auto compilation of Cg programs during rendering, etc. cgSetAutoCompile( m_Context, CG_COMPILE_MANUAL ); } ++m_RefCount; }
void InitCG(){ mCgContext = cgCreateContext(); checkForCgError("cgCreateContext()"); cgGLSetDebugMode(CG_FALSE); cgSetParameterSettingMode(mCgContext, CG_DEFERRED_PARAMETER_SETTING); checkForCgError("cgSetParameterSettingMode()"); mCgVertexProfile = cgGLGetLatestProfile(CG_GL_VERTEX); checkForCgError("cgGLGetLatestProfile()"); cgGLSetOptimalOptions(mCgVertexProfile); checkForCgError("cgGLSetOptimalOptions()"); mCgVertexProgram = cgCreateProgramFromFile(mCgContext, CG_SOURCE, "1tex_skin_mesh.cg", mCgVertexProfile, "skinMeshCG", NULL); checkForCgError("cgCreateProgramFromFile()"); cgGLLoadProgram(mCgVertexProgram); checkForCgError("cgGLLoadProgram()"); mBoneParameter = cgGetNamedParameter(mCgVertexProgram, "boneMatrix"); checkForCgError("cgGetNamedParameter(boneMatrix)"); }
void GLRenderer::Initialise() { RenderState rs; rs.state = RenderState::None; rs.matrixMode = -1; rs.target = 0; this->_PushState(rs); GLenum error = glewInit(); if (error != GLEW_OK) throw std::runtime_error(ToString("glewInit() failed: ") + ToString(glewGetErrorString(error))); if (!(GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader)) throw std::runtime_error("ARB_vertex_shader and ARB_fragment_shader are required"); Tools::log << "Glew version: " << (char const*)glewGetString(GLEW_VERSION) << "\n"; Tools::log << "OpenGL version: " << (char const*)glGetString(GL_VERSION) << "\n"; GLCHECK(glEnable(GL_BLEND)); //GLCHECK(glEnable(GL_ALPHA_TEST)); GLCHECK(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); //GLCHECK(glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); if (_cgGlobalContext == 0) _cgGlobalContext = cgCreateContext(); this->_cgContext = _cgGlobalContext; ++_cgGlobalNbReferences; cgSetErrorCallback(&ErrCallback); cgGLSetDebugMode(CG_FALSE); cgSetParameterSettingMode(this->_cgContext, CG_DEFERRED_PARAMETER_SETTING); cgGLRegisterStates(this->_cgContext); cgGLSetManageTextureParameters(this->_cgContext, CG_TRUE); InitDevIL(); GLCHECK(glCullFace(GL_FRONT)); }
int main(int argc, char **argv) { glutInitWindowSize(400, 400); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); glutInit(&argc, argv); glutCreateWindow(myProgramName); glutDisplayFunc(display); glutKeyboardFunc(keyboard); glClearColor(0.1, 0.3, 0.6, 0.0); /* Blue background */ myCgContext = cgCreateContext(); checkForCgError("creating context"); cgGLSetDebugMode(CG_FALSE); cgSetParameterSettingMode(myCgContext, CG_DEFERRED_PARAMETER_SETTING); myCgVertexProfile = cgGLGetLatestProfile(CG_GL_VERTEX); cgGLSetOptimalOptions(myCgVertexProfile); checkForCgError("selecting vertex profile"); myCgVertexProgram = cgCreateProgramFromFile( myCgContext, /* Cg runtime context */ CG_SOURCE, /* Program in human-readable form */ myVertexProgramFileName.c_str(), /* Name of file containing program */ myCgVertexProfile, /* Profile: OpenGL ARB vertex program */ myVertexProgramName, /* Entry function name */ NULL); /* No extra compiler options */ checkForCgError("creating vertex program from file"); cgGLLoadProgram(myCgVertexProgram); checkForCgError("loading vertex program"); glutMainLoop(); return 0; }
static void *gl_cg_init(void *data, const char *path) { unsigned i; cg_shader_data_t *cg_data = (cg_shader_data_t*) calloc(1, sizeof(cg_shader_data_t)); if (!cg_data) return NULL; #ifdef HAVE_CG_RUNTIME_COMPILER cgRTCgcInit(); #endif cg_data->cgCtx = cgCreateContext(); if (!cg_data->cgCtx) { RARCH_ERR("Failed to create Cg context.\n"); goto error; } #ifdef RARCH_CG_DEBUG cgGLSetDebugMode(CG_TRUE); cgSetErrorHandler(cg_error_handler, NULL); #endif cg_data->cgFProf = cgGLGetLatestProfile(CG_GL_FRAGMENT); cg_data->cgVProf = cgGLGetLatestProfile(CG_GL_VERTEX); if ( cg_data->cgFProf == CG_PROFILE_UNKNOWN || cg_data->cgVProf == CG_PROFILE_UNKNOWN) { RARCH_ERR("Invalid profile type\n"); free(cg_data); cg_data = NULL; goto error; } RARCH_LOG("[Cg]: Vertex profile: %s\n", cgGetProfileString(cg_data->cgVProf)); RARCH_LOG("[Cg]: Fragment profile: %s\n", cgGetProfileString(cg_data->cgFProf)); cgGLSetOptimalOptions(cg_data->cgFProf); cgGLSetOptimalOptions(cg_data->cgVProf); cgGLEnableProfile(cg_data->cgFProf); cgGLEnableProfile(cg_data->cgVProf); memset(cg_data->cg_alias_define, 0, sizeof(cg_data->cg_alias_define)); if (path && string_is_equal(path_get_extension(path), "cgp")) { if (!gl_cg_load_preset(cg_data, path)) goto error; } else { if (!gl_cg_load_plain(cg_data, path)) goto error; } cg_data->prg[0].mvp = cgGetNamedParameter(cg_data->prg[0].vprg, "IN.mvp_matrix"); for (i = 1; i <= cg_data->shader->passes; i++) gl_cg_set_program_attributes(cg_data, i); /* If we aren't using last pass non-FBO shader, * this shader will be assumed to be "fixed-function". * * Just use prg[0] for that pass, which will be * pass-through. */ cg_data->prg[cg_data->shader->passes + 1] = cg_data->prg[0]; /* No need to apply Android hack in Cg. */ cg_data->prg[GL_SHADER_STOCK_BLEND] = cg_data->prg[0]; cgGLBindProgram(cg_data->prg[1].fprg); cgGLBindProgram(cg_data->prg[1].vprg); return cg_data; error: gl_cg_destroy_resources(cg_data); if (!cg_data) free(cg_data); return NULL; }
int main(int argc, char **argv) { glutInitWindowSize(800, 800); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE); glutInit(&argc, argv); glutCreateWindow(myProgramName); glutDisplayFunc(display); glutKeyboardFunc(keyboard); glutReshapeFunc(reshape); glutMouseFunc(mouse); glClearColor(0.1, 0.1, 0.1, 0); /* Gray background. */ glEnable(GL_DEPTH_TEST); /* Hidden surface removal. */ myCgContext = cgCreateContext(); checkForCgError("creating context"); cgGLSetDebugMode( CG_FALSE ); myCgVertexProfile = cgGLGetLatestProfile(CG_GL_VERTEX); cgGLSetOptimalOptions(myCgVertexProfile); checkForCgError("selecting vertex profile"); myCgVertexProgram = cgCreateProgramFromFile( myCgContext, /* Cg runtime context */ CG_SOURCE, /* Program in human-readable form */ myVertexProgramFileName, /* Name of file containing program */ myCgVertexProfile, /* Profile: OpenGL ARB vertex program */ myVertexProgramName, /* Entry function name */ NULL); /* No extra commyPiler options */ checkForCgError("creating vertex program from file"); cgGLLoadProgram(myCgVertexProgram); checkForCgError("loading vertex program"); #define GET_VERTEX_PARAM(name) \ myCgVertexParam_##name = \ cgGetNamedParameter(myCgVertexProgram, #name); \ checkForCgError("could not get " #name " parameter"); GET_VERTEX_PARAM(modelViewProj); myCgFragmentProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT); cgGLSetOptimalOptions(myCgFragmentProfile); checkForCgError("selecting fragment profile"); myCgFragmentProgram = cgCreateProgramFromFile( myCgContext, /* Cg runtime context */ CG_SOURCE, /* Program in human-readable form */ myFragmentProgramFileName, myCgFragmentProfile, /* Profile: latest fragment profile */ myFragmentProgramName, /* Entry function name */ NULL); /* No extra commyPiler options */ checkForCgError("creating fragment program from string"); cgGLLoadProgram(myCgFragmentProgram); checkForCgError("loading fragment program"); #define GET_FRAGMENT_PARAM(name) \ myCgFragmentParam_##name = \ cgGetNamedParameter(myCgFragmentProgram, #name); \ checkForCgError("could not get " #name " parameter"); GET_FRAGMENT_PARAM(globalAmbient); GET_FRAGMENT_PARAM(lightColor); GET_FRAGMENT_PARAM(lightPosition); GET_FRAGMENT_PARAM(eyePosition); GET_FRAGMENT_PARAM(Ke); GET_FRAGMENT_PARAM(Ka); GET_FRAGMENT_PARAM(Kd); GET_FRAGMENT_PARAM(Ks); GET_FRAGMENT_PARAM(shininess); /* Set light source color parameters once. */ cgSetParameter3fv(myCgFragmentParam_globalAmbient, myGlobalAmbient); cgSetParameter3fv(myCgFragmentParam_lightColor, myLightColor); stickangle=90+angle; w.xspeed=0 ; w.zspeed=0; w.x=0;w.y=4;w.z=30; w.r=1;w.g=1;w.b=1; r.x=-34;r.y=4;r.z=-80; r.r=1;r.g=0;r.b=0; b.x=26;b.y=4;b.z=-40; b.r=0;b.g=0;b.b=0; w.flag=1; r.flag=1; b.flag=1; w.xspeed=0; w.zspeed=0; r.zspeed=0; r.xspeed=0; b.xspeed=0; b.zspeed=0; enablestick=1; printf("Billiards! By :\n"); printf("Prabhat Kumar Gupta\t 2007MCS2895\n"); printf("Nidhi Arora\t\t 2007MCS2913\t\n"); printf("-----------------------------------------------\n"); printf("\t\tControls\n"); printf("-----------------------------------------------\n"); printf("Control:\t\tAction\n"); printf("-----------------------------------------------\n"); printf("LeftClick/Spacebar\tEnable Stick and Strike\n"); printf("z\t\t\tRotate Stick Left\n"); printf("x\t\t\tRotate Stick Right\n"); printf("n\t\t\tZoom In\n"); printf("m\t\t\tZoom Out\n"); printf("1\t\t\tCamera 1\n"); printf("2\t\t\tCamera 2\n"); printf("3\t\t\tCamera 3\n"); printf("4\t\t\tCamera 4\n"); printf("-----------------------------------------------\n"); glutCreateMenu(menu); glutAddMenuEntry("[ ] Animate", ' '); glutAddMenuEntry("[ ] Camera1",'1'); glutAddMenuEntry("[ ] Camera2",'2'); glutAddMenuEntry("[ ] Camera3",'3'); glutAddMenuEntry("[ ] Camera4",'4'); glutAttachMenu(GLUT_RIGHT_BUTTON); glutMainLoop(); return 0; }
static bool gl_cg_init(const char *path) { unsigned i; #ifdef HAVE_CG_RUNTIME_COMPILER cgRTCgcInit(); #endif if (!cgCtx) cgCtx = cgCreateContext(); if (cgCtx == NULL) { RARCH_ERR("Failed to create Cg context\n"); return false; } #ifdef RARCH_CG_DEBUG cgGLSetDebugMode(CG_TRUE); cgSetErrorHandler(cg_error_handler, NULL); #endif cgFProf = cgGLGetLatestProfile(CG_GL_FRAGMENT); cgVProf = cgGLGetLatestProfile(CG_GL_VERTEX); if (cgFProf == CG_PROFILE_UNKNOWN || cgVProf == CG_PROFILE_UNKNOWN) { RARCH_ERR("Invalid profile type\n"); goto error; } #ifndef HAVE_RGL RARCH_LOG("[Cg]: Vertex profile: %s\n", cgGetProfileString(cgVProf)); RARCH_LOG("[Cg]: Fragment profile: %s\n", cgGetProfileString(cgFProf)); #endif cgGLSetOptimalOptions(cgFProf); cgGLSetOptimalOptions(cgVProf); cgGLEnableProfile(cgFProf); cgGLEnableProfile(cgVProf); if (path && strcmp(path_get_extension(path), "cgp") == 0) { if (!load_preset(path)) goto error; } else { if (!load_plain(path)) goto error; } prg[0].mvp = cgGetNamedParameter(prg[0].vprg, "IN.mvp_matrix"); for (i = 1; i <= cg_shader->passes; i++) set_program_attributes(i); // If we aren't using last pass non-FBO shader, // this shader will be assumed to be "fixed-function". // Just use prg[0] for that pass, which will be // pass-through. prg[cg_shader->passes + 1] = prg[0]; // No need to apply Android hack in Cg. prg[GL_SHADER_STOCK_BLEND] = prg[0]; cgGLBindProgram(prg[1].fprg); cgGLBindProgram(prg[1].vprg); cg_active = true; return true; error: gl_cg_deinit(); return false; }