Jump to content
  • Advertisement
Sign in to follow this  
zix99

CG Not working so well...

This topic is 4839 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone (again), I've ran onto a problem with my CG script (it simply doesn't work). I'm currently using a Fragment Shader on a water plane. With the shader turned off the plane is visible, with it turned on it's not even drawn (doesnt even affect the depth buffer as far as i can tell). The CG Source:
float4 main(float2 normalCoords : TEXCOORD0,
		float2 refCoords : TEXCOORD1,
		uniform sampler2D normalTex : TEXUNIT0,
		uniform sampler2D refTex : TEXUNIT1): COLOR
{
	float4 ret;
	ret.rgb = tex2D(refTex, refCoords).rgb;
	ret.a = 1.0;
	return ret;
}

(I took much of the real source out so it's simple) I believe my problem is in my loading or displaying code Loading/initialize code:
#include "cgman.h"
#include "file_functions.h"
#include <stdio.h>
#include <cg/cg.h>
#include <cg/cggl.h>

CGcontext cgContext;
CGprofile cgVertexProfile;
CGprofile cgFragmentProfile;

//initializing and exiting a CG context
void cgmInitialize(){
	cgContext = cgCreateContext();
	if (cgContext == 0){
		MessageBox(NULL, "Error starting CG, check to make sure cg.dll is present!", "ERROR", MB_OK);
		exit(1);
	}
	cgVertexProfile = cgGLGetLatestProfile(CG_GL_VERTEX);
	cgFragmentProfile=cgGLGetLatestProfile(CG_GL_FRAGMENT);

}
void cgmUnload(){
	cgDestroyContext(cgContext);
}


//Loading a script
CGprogram cgmLoadProgram(const char *filename, int program_type){
	CGprogram ret;

	ExtractToTemp("data/cg.pak", filename);
	char fname[256];
	sprintf(fname, "temp/%s", filename);

	if (program_type == CGM_VERTEX){
		cgGLSetOptimalOptions(cgVertexProfile);
		ret = cgCreateProgramFromFile(cgContext, CG_SOURCE, fname, cgVertexProfile, "main", 0);
	}else if(program_type == CGM_FRAGMENT){
		cgGLSetOptimalOptions(cgFragmentProfile);
		ret = cgCreateProgramFromFile(cgContext, CG_SOURCE, fname, cgFragmentProfile, "main", 0);
	}else{
		return NULL;
	}
	if (ret == NULL){
		CGerror Error = cgGetError();
		MessageBox(NULL, cgGetErrorString(Error), "ERROR", MB_OK);
		cgmUnload();
		exit(1);
	}
	return ret;
}

And display:
void water_Draw(){


	//enable CG
	cgGLEnableProfile(cgFragmentProfile);
	cgGLBindProgram(water_reflection);


	//enable texture units
	glActiveTextureARB(GL_TEXTURE0_ARB);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, waterdetail); //bumpmap

	glActiveTextureARB(GL_TEXTURE1_ARB);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, watertex); //overlay texture


	//draw
	glBegin(GL_QUADS);
		glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0f, 0.0f);
		glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0f, 0.0f);
		glVertex3f(water_offx, water_offy, opfile.waterlevel);

		glMultiTexCoord2fARB(GL_TEXTURE0_ARB, SIGHT/4.0f, 0.0f);
		glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0f, 0.0f);
		glVertex3f(water_offx+SIGHT*2.0f, water_offy, opfile.waterlevel);

		glMultiTexCoord2fARB(GL_TEXTURE0_ARB, SIGHT/4.0f, SIGHT/4.0f);
		glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0f,1.0f);
		glVertex3f(water_offx+SIGHT*2.0f, water_offy+SIGHT*2.0f, opfile.waterlevel);

		glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0f, SIGHT/4.0f);
		glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0f, 1.0f);
		glVertex3f(water_offx, water_offy+SIGHT*2.0f, opfile.waterlevel);
	glEnd();


	//disable texture units
	glActiveTextureARB(GL_TEXTURE1_ARB);
	glDisable(GL_TEXTURE_2D);
	glActiveTextureARB(GL_TEXTURE0_ARB);

	//disable CG
	cgGLDisableProfile(cgFragmentProfile);
}

Thanks for your help, once again ~zix~

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!