void Shader::Apply() { if (vertex_program) { cgGLSetStateMatrixParameter(cgGetNamedParameter(vertex_program, "ModelViewProj"), CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY); cgGLBindProgram(vertex_program); cgGLEnableProfile(vertex_profile); } else { cgGLDisableProfile(vertex_profile); } if (fragment_program) { GLint handle; CGparameter param; glGetIntegerv(GL_TEXTURE_BINDING_2D, &handle); param = cgGetNamedParameter(fragment_program, "Decal"); cgGLSetTextureParameter(param, handle); cgGLEnableTextureParameter(param); cgGLBindProgram(fragment_program); cgGLEnableProfile(fragment_profile); } else { cgGLDisableProfile(fragment_profile); } }
int32_t PS3Graphics::LoadFragmentShader(std::string shaderPath) { // store the current path _curFragmentShaderPath = shaderPath; _vertexProgram = LoadShaderFromSource(_cgContext, CG_PROFILE_SCE_VP_RSX, shaderPath.c_str(), "main_vertex"); _fragmentProgram = LoadShaderFromSource(_cgContext, CG_PROFILE_SCE_FP_RSX, shaderPath.c_str(), "main_fragment"); // bind and enable the vertex and fragment programs cgGLEnableProfile(CG_PROFILE_SCE_VP_RSX); cgGLEnableProfile(CG_PROFILE_SCE_FP_RSX); cgGLBindProgram(_vertexProgram); cgGLBindProgram(_fragmentProgram); // acquire mvp param from vertex shader _cgpModelViewProj = cgGetNamedParameter(_vertexProgram, "modelViewProj"); _cgpVideoSize = cgGetNamedParameter(_fragmentProgram, "IN.video_size"); _cgpTextureSize = cgGetNamedParameter(_fragmentProgram, "IN.texture_size"); _cgpOutputSize = cgGetNamedParameter(_fragmentProgram, "IN.output_size"); if (active_shader) lib_free(active_shader); active_shader = util_concat(shaderPath.c_str(), NULL); return CELL_OK; }
void cgtk::raycasting_pass() { disable_renderbuffers(); //glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_COLOR_ATTACHMENT0_EXT,GL_TEXTURE_RECTANGLE_ARB,final_image,0); //glClearColor(0,0,0,0); //glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); cgGLEnableProfile(vertexProfile); cgGLEnableProfile(fragmentProfile); cgGLBindProgram(vertex_main); cgGLBindProgram(fragment_main); cgGLSetParameter1f(cgGetNamedParameter(fragment_main,"stepsize"),stepsize); cgGLSetParameter1f(cgGetNamedParameter(fragment_main,"width"),WINDOW_SIZE_W); cgGLSetParameter1f(cgGetNamedParameter(fragment_main,"heigth"),WINDOW_SIZE_H); set_tex_param("tex",backface_buffer,fragment_main,param1); set_tex_param("volume_tex",volume_texture,fragment_main,param2); glEnable(GL_BLEND); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); //drawQuads(1,1,1,b); drawBd(); cgGLDisableProfile(vertexProfile); cgGLDisableProfile(fragmentProfile); glDisable(GL_CULL_FACE); glDisable(GL_BLEND); }
void CG_RENDER_CUBEMAP(void) { glPushMatrix(); glTranslatef(0, 0.0f, 1.5f); //glRotatef(spinFloat -25, 0.0f, 0.0f, 1.0f); spinFloat += 0.0; glRotatef(90, 1.0, 0.0,0.0); cgGLBindProgram( cgVertexProgram ); cgGLBindProgram( cgFragmentProgram ); cgGLEnableProfile( cgVertexProfile ); cgGLEnableProfile( cgFragmentProfile ); cgGLEnableTextureParameter( cgEnvironmentMap ); cgGLSetStateMatrixParameter( cgModelViewProj, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY ); cgGLSetStateMatrixParameter( cgModelView, CG_GL_MODELVIEW_MATRIX, CG_GL_MATRIX_IDENTITY ); cgGLSetStateMatrixParameter( cgModelViewI, CG_GL_MODELVIEW_MATRIX, CG_GL_MATRIX_INVERSE ); cgGLSetStateMatrixParameter( cgModelViewIT, CG_GL_MODELVIEW_MATRIX, CG_GL_MATRIX_INVERSE_TRANSPOSE ); glInterleavedArrays( GL_T2F_N3F_V3F, 0, MeTooB); glDrawArrays( GL_TRIANGLES, 0, 7608); cgGLDisableTextureParameter( cgEnvironmentMap ); cgGLDisableProfile( cgVertexProfile ); cgGLDisableProfile( cgFragmentProfile ); glPopMatrix(); }
void ShaderSystem::enableProfiles() { cgGLEnableProfile(fragmentProfile); checkError("enabling fragment profile"); cgGLEnableProfile(vertexProfile); checkError("enabling vertex profile"); }
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); }
void COpenGLCgMaterialRenderer::OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, bool resetAllRenderstates, IMaterialRendererServices* services) { Material = material; if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) { if (VertexProgram) { cgGLEnableProfile(VertexProfile); cgGLBindProgram(VertexProgram); } if (FragmentProgram) { cgGLEnableProfile(FragmentProfile); cgGLBindProgram(FragmentProgram); } if (GeometryProgram) { cgGLEnableProfile(GeometryProfile); cgGLBindProgram(GeometryProgram); } if (BaseMaterial) BaseMaterial->OnSetMaterial(material, material, true, this); } if (CallBack) CallBack->OnSetMaterial(material); Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); }
void Cg::Enable(){ /* テクスチャ1をアクティブにする*/ cgGLEnableTextureParameter(vdecalParam); cgGLEnableTextureParameter(fdecalParam); //cg有効化 cgGLEnableProfile(vertexProfile);CheckCgError(); cgGLEnableProfile(fragmentProfile);CheckCgError(); }
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; }
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; }
static void fshader_select (int select_in) { FShader* s; Env* e; fshader_selected = select_in - FSHADER_BASE; if (fshader_selected == -1 || !CVarUtils::GetCVar<bool> ("render.textured")) { cgGLDisableProfile (cgp_fragment); return; } if (!CVarUtils::GetCVar<bool> ("render.shaders")) return; s = &fshader_list[fshader_selected]; e = EnvGet (); cgGLEnableProfile (cgp_fragment); cgGLBindProgram (s->program); if (select_in == FSHADER_CLOUDS) { GLrgba c = (e->color[ENV_COLOR_SKY] + e->color[ENV_COLOR_HORIZON]) / 2.0f; cgGLSetParameter3f (s->fogcolor, c.red, c.green, c.blue); } else cgGLSetParameter3f (s->fogcolor, e->color[ENV_COLOR_FOG].red, e->color[ENV_COLOR_FOG].green, e->color[ENV_COLOR_FOG].blue); cgGLSetTextureParameter (s->texture, TextureIdFromName ("clouds.png")); cgGLSetParameter4f (s->data, wind, e->cloud_cover, 1 - e->star_fade, 0); cgGLEnableTextureParameter (s->texture); }
//--------------------------------------------------------------------------------- // bind vertex/fragment program // PSGL specific //--------------------------------------------------------------------------------- void FFxProgram::bind() { if (!mProgram) return; #ifdef WIN32 if (GDD->GetClassID() == ClassIDZDisplayDeviceDX9) { HRESULT hr = cgD3D9BindProgram(mProgram); /* if (mProfile == CG_PROFILE_VS_2_0) { HRESULT hr = GDD->GetD3D9Device()->SetVertexShader((IDirect3DVertexShader9*)mDXShader->GetBufferPointer()); int a = 1; } else { GDD->GetD3D9Device()->SetPixelShader((IDirect3DPixelShader9*)mDXShader->GetBufferPointer()); } */ } else #endif { cgGLEnableProfile(mProfile); cgGLBindProgram(mProgram); } }
void board_update() { cgGLEnableProfile(cg__fragmentProfile); cgGLBindProgram(cg__fragmentProgram); // transfer data to texture texture_load_array(board__computeTexture, GL_TEXTURE_RECTANGLE_ARB, board__width, board__width, board__data); // perform computation CGparameter textureCg = cgGetNamedParameter(cg__fragmentProgram, "aBoard"); cgGLSetTextureParameter(textureCg, board__computeTexture); cgGLEnableTextureParameter(textureCg); CGparameter widthCg = cgGetNamedParameter(cg__fragmentProgram, "aWidth"); cgSetParameter1f(widthCg, board__width); board_draw(); // GPGPU CONCEPT 4: Viewport-Sized Quad = Data Stream Generator. cgGLDisableTextureParameter(textureCg); cgGLDisableProfile(cg__fragmentProfile); // Read back the results glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); // The glReadBuffer function selects a color buffer source for pixels. // void glReadBuffer(GLenum mode); mode is a color buffer // The glReadPixels function reads a block of pixels from the framebuffer. glReadPixels( 0, 0, // GLint x, y The window coordinates of the first pixel that is read from the framebuffer. This location is the lower-left corner of a rectangular block of pixels board__width, // GLsizei width board__width, // GLsizei height GL_RGBA, // GLenum format GL_FLOAT, // GLenum type board__data); // GLvoid *pixels }
void FreezeParticle::Render(float x, float y, float z, float theta, float thetaX, float thetaY, float thetaZ) { glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); cgGLEnableProfile(FreezeParticleProfile); cgGLBindProgram(FreezeParticleProgram); cgGLEnableTextureParameter(FreezeParticleText1); glPushMatrix(); glTranslatef(x,y,z); glTranslatef(mPos.GetX(), mPos.GetY(), mPos.GetZ()); glRotatef(mRotate, 0.2f, 0.5f, 1); glRotatef(theta, thetaX, thetaY, thetaZ); glScalef((30-mLife)/30,(30-mLife)/30,(30-mLife)/30); glBegin(GL_TRIANGLES); glTexCoord3f(0,0,0); glVertex3f(-3,0,0); glTexCoord3f(.5,1,0); glVertex3f(0, 3, 0); glTexCoord3f(0,0,0); glVertex3f(1, 0, 0); glEnd(); glPopMatrix(); cgGLDisableProfile(FreezeParticleProfile); }
void CgShaderProgramGL::bind() { if (!ParameterMap_.empty()) cgUpdateProgramParameters(cgProgram_); cgGLBindProgram(cgProgram_); cgGLEnableProfile(cgProfile_); }
void ShaderCG::preRender(Renderer* renderer) { #ifdef HAS_CG if (!use_cg) return; cgGLEnableProfile(profile_vertex); cgGLEnableProfile(profile_fragment); cgGLBindProgram(program_vertex); cgGLBindProgram(program_fragment); if(g_modelViewProjMatrix != NULL) cgGLSetStateMatrixParameter(g_modelViewProjMatrix, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY); if(g_modelViewMatrix != NULL) cgGLSetStateMatrixParameter(g_modelViewMatrix, CG_GL_MODELVIEW_MATRIX, CG_GL_MATRIX_IDENTITY); if(g_modelViewMatrixI != NULL) cgGLSetStateMatrixParameter(g_modelViewMatrixI, CG_GL_MODELVIEW_MATRIX, CG_GL_MATRIX_INVERSE); if(g_modelViewMatrixIT != NULL) cgGLSetStateMatrixParameter(g_modelViewMatrixIT, CG_GL_MODELVIEW_MATRIX, CG_GL_MATRIX_INVERSE_TRANSPOSE); Light light; renderer->getLight(&light, 0); if(g_lightDiffuse != NULL) cgGLSetParameter4fv(g_lightDiffuse, light.getDiffuse()); if(g_lightPosition != NULL) cgGLSetParameter4fv(g_lightPosition, light.getPos()); /* if(g_lightAmbiente != NULL) cgGLSetParameter4fv(g_lightAmbiente, light.getAmbiente()); if(g_lightSpecular != NULL) cgGLSetParameter4fv(g_lightSpecular, light.getSpecular()); */ ErrorCheck(); glDisable(GL_LIGHTING); #endif // HAS_CG }
void cgShader_3::Enable(){ for(int k = 0; k < 5; k++){ if(cgProgram[k]){ cgGLEnableProfile(cgProfile[k]); cgGLBindProgram(cgProgram[k]); } } }
int32_t FceuGraphics::LoadFragmentShader(string shaderPath) { LOG_DBG("LoadFragmentShader(%s)\n", shaderPath.c_str()); // store the cur path _curFragmentShaderPath = shaderPath; _vertexProgram = LoadShaderFromSource(_cgContext, CG_PROFILE_SCE_VP_RSX, shaderPath.c_str(), "main_vertex"); if (_vertexProgram <= 0) { LOG_DBG("Error loading vertex shader..."); return 1; } _fragmentProgram = LoadShaderFromSource(_cgContext, CG_PROFILE_SCE_FP_RSX, shaderPath.c_str(), "main_fragment"); if (_fragmentProgram <= 0) { LOG_DBG("Error loading fragment shader..."); return 1; } // bind and enable the vertex and fragment programs cgGLEnableProfile(CG_PROFILE_SCE_VP_RSX); cgGLEnableProfile(CG_PROFILE_SCE_FP_RSX); cgGLBindProgram(_vertexProgram); cgGLBindProgram(_fragmentProgram); // acquire mvp param from v shader _cgpModelViewProj = cgGetNamedParameter(_vertexProgram, "modelViewProj"); if (CheckCgError (__LINE__) != CG_NO_ERROR) { // FIXME: WHY DOES THIS GIVE ERROR ON OTHER LOADS //return 1; } _cgpVideoSize = cgGetNamedParameter(_fragmentProgram, "IN.video_size"); _cgpTextureSize = cgGetNamedParameter(_fragmentProgram, "IN.texture_size"); _cgpOutputSize = cgGetNamedParameter(_fragmentProgram, "IN.output_size"); LOG_DBG("SUCCESS - LoadFragmentShader(%s)\n", shaderPath.c_str()); return CELL_OK; }
///\brief Returns the sum of the texture data. void Sum::getSum(GLuint texInput,double *result,bool perChannel) { int previousViewportDims[4] ; glMatrixMode(GL_PROJECTION); glPushMatrix(); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glGetIntegerv(GL_VIEWPORT, previousViewportDims ); int lvl =1; glEnable(GL_TEXTURE_RECTANGLE_NV); glClear(GL_DEPTH_BUFFER_BIT); cgGLEnableProfile(cgProfile); glActiveTextureARB(GL_TEXTURE0_ARB); for( lvl=1 ; lvl<=N_REDUCE; lvl++ ) { glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb[lvl-1]); if( lvl == 1 ) { reduce(texInput, (int)sizes[lvl-1].x(), (int)sizes[lvl-1].y(), (int)sizes[lvl].x(), (int)sizes[lvl].y() ); } else { reduce(tex[lvl-2], (int)sizes[lvl-1].x(), (int)sizes[lvl-1].y(), (int)sizes[lvl].x(), (int)sizes[lvl].y() ); } //glReadPixels( 0, 0,width/2,height/2, GL_RGBA, GL_FLOAT, rbbuf); //cerr<<sumBuf(rbbuf,width/32,height/32,4); } int rbW = (int)sizes[lvl-1].x(); int rbH = (int)sizes[lvl-1].y(); // cerr<<"Reading back "<<rbW<<"x"<<rbH<<endl; glReadPixels( 0, 0,rbW, rbH, GL_RGBA, GL_FLOAT, rbbuf); if( perChannel ) { sumBuf4( rbbuf,rbW, rbH,4, &(result[0]), &(result[1]), &(result[2]), &(result[3]) ); } else { *result = sumBuf(rbbuf,rbW, rbH,4); } /* todo : rebind original callingframebuffer and texture state */ /* todo : push pop matrices */ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0 ); glActiveTextureARB(GL_TEXTURE0_ARB); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glViewport( previousViewportDims[0], previousViewportDims[1], previousViewportDims[2], previousViewportDims[3] ); cgGLDisableProfile(cgProfile); return; }
void ParticleShaderDiskDevelop::drawParticle(int i) { cgGLEnableProfile(vProfile); cgGLEnableProfile(fProfile); cgGLBindProgram(vProgram); bindCGParametersVertex(); bindCGParametersFragment(); cgGLBindProgram(fProgram); GLfloat lightpos[4]; glGetLightfv(GL_LIGHT0, GL_POSITION, lightpos); cgGLSetParameter4fv(lightPositionEC, lightpos); // Pull the diffuse color GLfloat diff[4]; glGetMaterialfv(GL_FRONT, GL_DIFFUSE, diff); // Set the disk center GLfloat dC[3] = {0.0, 0.0, 0.0}; // Get the radius if (radius_data) radius = (*radius_data)[i]; else radius = 1.0; // Set the per-particle Cg parameters cgGLSetParameter3fv(diskCenterWC, dC); cgGLSetParameter4fv(diffuseColor, diff); cgGLSetParameter1f(diskRadius, GLfloat(radius * scale)); cgGLSetStateMatrixParameter(modelViewProj, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY); cgGLSetStateMatrixParameter(modelView, CG_GL_MODELVIEW_MATRIX, CG_GL_MATRIX_IDENTITY); cgGLSetStateMatrixParameter(modelViewIT, CG_GL_MODELVIEW_MATRIX, CG_GL_MATRIX_INVERSE_TRANSPOSE); gluDisk(quad,0,radius*scale*1.51,4,4); cgGLDisableProfile(vProfile); cgGLDisableProfile(fProfile); }
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 ObjMeshGPUDeformer::RenderEdges() { glDisable(GL_TEXTURE_2D); cgGLEnableProfile(VertexProfile); cgGLBindProgram(VertexPass2ProgramEdges); cgGLSetStateMatrixParameter(ModelViewProjEdgeParam, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY); cgGLSetStateMatrixParameter(ModelViewITEdgeParam, CG_GL_MODELVIEW_MATRIX, CG_GL_MATRIX_INVERSE_TRANSPOSE); glBindTexture(GL_TEXTURE_2D, vertexDeformationTextureID); BindRT(); #ifdef OBJMESHGPUDEFORMER_USING_VBOS glEnableClientState(GL_VERTEX_ARRAY); glClientActiveTextureARB(GL_TEXTURE0_ARB); glEnableClientState(GL_TEXTURE_COORD_ARRAY); for(int groupNo=0; groupNo<numGroups; groupNo++) { // render via VBOs glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboEdgesID[3*groupNo+0]); glVertexPointer(3, GL_FLOAT, 0, 0); glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboEdgesID[3*groupNo+1]); glTexCoordPointer(2, GL_FLOAT, 0, 0); glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, vboEdgesID[3*groupNo+2]); int numGroupEdges = 3 * numGroupTriangles[groupNo]; glDrawElements(GL_LINES, 2 * numGroupEdges, GL_UNSIGNED_INT, 0); } // unbind VBOs glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); #else for(int groupNo=0; groupNo<numGroups; groupNo++) glCallList(displayListEdgesStart + groupNo); #endif UnbindRT(); cgGLDisableProfile(VertexProfile); }
void DrawSea() { seatime=seatime+1.0f/2400.0f; if(seatime>1.0f) seatime=seatime-1.0f; cgSetParameter1f(cgGetNamedParameter( g_Sea_vertex, "time"), seatime); g_CGparam_AmbientReflectiveSea = cgGetNamedParameter(g_Sea_pixel, "AmbientReflectiveTexturSea"); cgGLSetTextureParameter( g_CGparam_AmbientReflectiveSea, AmbientReflectiveTexture ); cgSetParameter3fv(cgGetNamedParameter( g_Sea_pixel, "globalAmbient" ), globalAmbient); cgSetParameter3fv(cgGetNamedParameter( g_Sea_pixel, "paraLightColor" ), paraLightColor); cgSetParameter3fv(cgGetNamedParameter( g_Sea_pixel, "paraLightDirection" ), LightSunPos); cgSetParameter3fv(cgGetNamedParameter( g_Sea_pixel, "eyePosition"), eyePositionSea); cgSetParameter3fv(cgGetNamedParameter( g_Sea_pixel, "FogColor"), pixelfogColor); //cgSetParameter1f(cgGetNamedParameter( g_Sea_pixel, "time"), seatime); cgGLBindProgram( g_Sea_vertex ); cgGLEnableProfile( g_CGprofile_vertex ); cgGLBindProgram( g_Sea_pixel ); cgGLEnableProfile( g_CGprofile_pixel ); cgGLEnableTextureParameter( g_CGparam_AmbientReflectiveSea ); }
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); }
void COpenGLCgMaterialRenderer::OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, bool resetAllRenderstates, IMaterialRendererServices* services) { if (Driver->getFixedPipelineState() == COpenGLDriver::EOFPS_ENABLE) Driver->setFixedPipelineState(COpenGLDriver::EOFPS_ENABLE_TO_DISABLE); else Driver->setFixedPipelineState(COpenGLDriver::EOFPS_DISABLE); if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) { if (VertexProgram) { cgGLEnableProfile(VertexProfile); cgGLBindProgram(VertexProgram); } if (FragmentProgram) { cgGLEnableProfile(FragmentProfile); cgGLBindProgram(FragmentProgram); } if (GeometryProgram) { cgGLEnableProfile(GeometryProfile); cgGLBindProgram(GeometryProgram); } } Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); if (BaseMaterial) BaseMaterial->OnSetBaseMaterial(material); if (CallBack) CallBack->OnSetMaterial(material); Material = material; }
bool GLCgShader::SetShader() { cgGLBindProgram(m_cgProgam); if (CheckForError("cgGLBindProgram", m_shaderName)) return false; cgUpdateProgramParameters(m_cgProgam); if (CheckForError("cgUpdateProgramParameters", m_shaderName)) return false; cgGLEnableProfile(m_cgProfile); if (CheckForError("cgGLEnableProfile", m_shaderName)) return false; return true; }
void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); cgGLBindProgram(cg_vertex_program); checkForCgError("binding vertex program"); cgGLEnableProfile(cg_vertex_profile); checkForCgError("enabling vertex profile"); // parameter //cgGLSetParameter1f(cg_parameter_vertex_scale_factor, 0.7); //cgGLSetParameter1f(cg_parameter_vertex_rotation, rotation); // Zeit die seit dem rendern des letzten Bildes vergangen ist: cgGLEnableTextureParameter(cg_parameter_vertex_time); t = diff_seconds(); glVertex2f(0.0f, 0.0f); glTexCoord1f(Particle->t); cgGLDisableTextureParameter(cg_parameter_vertex_time); // Berechnung der Framerate mit Hilfe der Zeitmessungsfunktion: frames++; timer += t; if (timer > 1.0) { printf("Frames per second: %i\n", frames); timer -= 1.0; frames = 0; printf("Number of particles: %d\n", water_list.size()); } //cgGLEnableTextureParameter(cg_parameter_vertex_velocity); drawParticles(water_list,water_tex); //glVertex2f(0.0f, 0.0f); //glTexCoord3fv(Particle->velocity); //cgGLDisableTextureParameter(cg_parameter_vertex_velocity); cgGLDisableProfile(cg_vertex_profile); checkForCgError("disabling vertex profile"); glutSwapBuffers(); }
void CgStartDrawCallback::operator()( osg::RenderInfo& renderInfo ) const { if ( !_initialized ) { for ( unsigned int i=0; i<_programs.size(); ++i ) { cgGLLoadProgram( _programs[i] ); } _initialized = true; } for ( unsigned int i=0; i<_programs.size(); ++i ) { cgGLBindProgram( _programs[i] ); } for ( unsigned int i=0; i<_profiles.size(); ++i ) { cgGLEnableProfile( _profiles[i] ); } }
void ObjMeshGPUDeformer::RenderVertices() { glDisable(GL_TEXTURE_2D); cgGLEnableProfile(VertexProfile); cgGLBindProgram(VertexPass2ProgramPoints); cgGLSetStateMatrixParameter(ModelViewProjPointParam, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY); cgGLSetStateMatrixParameter(ModelViewITPointParam, CG_GL_MODELVIEW_MATRIX, CG_GL_MATRIX_INVERSE_TRANSPOSE); glBindTexture(GL_TEXTURE_2D, vertexDeformationTextureID); BindRT(); glCallList(displayListPoints); UnbindRT(); cgGLDisableProfile(VertexProfile); }
static void vshader_select (int select) { VShader* s; GLvector p; Env* e; GLrgba c; float val1, val2; vshader_selected = select; if (!CVarUtils::GetCVar<bool> ("render.shaders")) return; if (select == VSHADER_NONE) { cgGLDisableProfile (cgp_vertex); return; } val1 = val2 = 0.0f; if (select == VSHADER_TREES || select == VSHADER_GRASS) val1 = wind; if (select == VSHADER_CLOUDS) val1 = wind / 5; s = &vshader_list[select]; e = EnvGet (); cgGLEnableProfile (cgp_vertex); cgGLBindProgram (s->program); cgGLSetParameter3f (s->lightpos, -e->light.x, -e->light.y, -e->light.z); c = e->color[ENV_COLOR_LIGHT]; cgGLSetParameter3f (s->lightcol, c.red, c.green, c.blue); c = e->color[ENV_COLOR_AMBIENT] * glRgba (0.2f, 0.2f, 1.0f); cgGLSetParameter3f (s->ambientcol, c.red, c.green, c.blue); p = AvatarCameraPosition (); cgGLSetParameter3f (s->eyepos, p.x, p.y, p.z); cgGLSetStateMatrixParameter(s->matrix, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MODELVIEW_MATRIX); cgGLSetParameter2f (s->fog, e->fog.rmin, e->fog.rmax); cgGLSetParameter4f (s->data, SceneVisibleRange (), SceneVisibleRange () * 0.05, val1, val2); glColor3f (1,1,1); }