Esempio n. 1
0
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 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();
}
Esempio n. 3
0
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);
    }
}
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);
}
Esempio n. 5
0
void DoBlur(unsigned int uiSrcTex, unsigned int uiTargetTex, int srcTexWidth, int srcTexHeight, int destTexWidth, int destTexHeight, float xofs, float yofs)
{
	cgGLBindProgram(g_cgVP_GlowBlur);
	cgGLBindProgram(g_cgFP_GlowBlur);

	pglActiveTextureARB(GL_TEXTURE0_ARB);
	glEnable(GL_TEXTURE_RECTANGLE_NV);
	glBindTexture(GL_TEXTURE_RECTANGLE_NV, uiSrcTex);

	pglActiveTextureARB(GL_TEXTURE1_ARB);
	glEnable(GL_TEXTURE_RECTANGLE_NV);
	glBindTexture(GL_TEXTURE_RECTANGLE_NV, uiSrcTex);

	pglActiveTextureARB(GL_TEXTURE2_ARB);
	glEnable(GL_TEXTURE_RECTANGLE_NV);
	glBindTexture(GL_TEXTURE_RECTANGLE_NV, uiSrcTex);

	pglActiveTextureARB(GL_TEXTURE3_ARB);
	glEnable(GL_TEXTURE_RECTANGLE_NV);
	glBindTexture(GL_TEXTURE_RECTANGLE_NV, uiSrcTex);

	cgGLSetParameter1f(g_cgpVP1_XOffset, xofs);
	cgGLSetParameter1f(g_cgpVP1_YOffset, yofs);

	glViewport(0, 0, destTexWidth, destTexHeight);

	DrawQuad(srcTexWidth, srcTexHeight);

	glBindTexture(GL_TEXTURE_RECTANGLE_NV, uiTargetTex);
	glCopyTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGB, 0, 0, destTexWidth, destTexHeight, 0);
}
Esempio n. 6
0
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);
}
Esempio n. 7
0
static void gl_cg_use(unsigned index)
{
   if (cg_active && prg[index].vprg && prg[index].fprg)
   {
      gl_cg_reset_attrib();

      active_index = index;
      cgGLBindProgram(prg[index].vprg);
      cgGLBindProgram(prg[index].fprg);
   }
}
Esempio n. 8
0
static void gl_cg_use(void *data, void *shader_data, unsigned idx)
{
   cg_shader_data_t *cg_data = (cg_shader_data_t*)shader_data;
   if (cg_data && cg_data->prg[idx].vprg && cg_data->prg[idx].fprg)
   {
      gl_cg_reset_attrib(cg_data);

      cg_data->active_idx = idx;
      cgGLBindProgram(cg_data->prg[idx].vprg);
      cgGLBindProgram(cg_data->prg[idx].fprg);
   }
}
Esempio n. 9
0
static void gl_cg_use(void *data, unsigned idx)
{
   cg_shader_data_t *cg = (cg_shader_data_t*)driver.video_shader_data;
   (void)data;

   if (cg && cg->prg[idx].vprg && cg->prg[idx].fprg)
   {
      gl_cg_reset_attrib(cg);

      cg->active_idx = idx;
      cgGLBindProgram(cg->prg[idx].vprg);
      cgGLBindProgram(cg->prg[idx].fprg);
   }
}
Esempio n. 10
0
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);
}
Esempio n. 11
0
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
}
Esempio n. 12
0
//---------------------------------------------------------------------------------
// 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);
	}
}
Esempio n. 13
0
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);
}
Esempio n. 14
0
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);

}
Esempio n. 15
0
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
}
Esempio n. 16
0
void cgShader_3::Enable(){
    for(int k = 0; k < 5; k++){
        if(cgProgram[k]){
            cgGLEnableProfile(cgProfile[k]);
            cgGLBindProgram(cgProgram[k]);
        }
    }
}
void CgShaderProgramGL::bind()
{
    if (!ParameterMap_.empty())
        cgUpdateProgramParameters(cgProgram_);

    cgGLBindProgram(cgProgram_);
    cgGLEnableProfile(cgProfile_);
}
Esempio n. 18
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;
}
void Cg::BindProgram(CGprogram program){
	if(program != NULL)
		cgGLBindProgram(program);
	else
	{
		cout<<"CGparameter is null"<<endl;
		abort();
	}
	CheckCgError();
}
Esempio n. 20
0
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;
}
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);
}
Esempio n. 22
0
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);
}
Esempio n. 23
0
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 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;
}
Esempio n. 25
0
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;
}
Esempio n. 26
0
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();
}
Esempio n. 27
0
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] );
    }
}
Esempio n. 28
0
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);
}
Esempio n. 29
0
 //
 // Set
 //
 void CCgShadingProgram::Set() const
 {
     cgGLBindProgram( m_Program );
 #ifdef _DEBUG
     CGerror Error = cgGetError();
     if (Error != CG_NO_ERROR)
         throw CCgException( this, Error, "::Set() : A Cg error has occured." );
 #endif
     
     if (!m_FeedbackAttribs.empty())
     {
 #ifdef _DEBUG
         glClearErrors();
 #endif
         glTransformFeedbackAttribsNV( static_cast<GLsizei>( m_FeedbackAttribs.size() / 3 ), &m_FeedbackAttribs[ 0 ], m_FeedbackMode );
 #ifdef _DEBUG
         GLenum Error = glGetError();
         if (Error != GL_NO_ERROR)
             throw CException( this, Error, "::Set() : An OpenGL error has occured." );
 #endif
     }
 }
Esempio n. 30
0
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);

}