Exemplo n.º 1
0
bool KernelDebug::Prepare()
{
  ReserveSlots(KERNEL_DEBUG_MODE_COUNT);

  if (!LoadVertexProgram  (KERNEL_DEBUG_MODE_TEST1, SHADER_DIR "/" "kernel_debug1_vp.cg.shd")) return false;
  if (!LoadFragmentProgram(KERNEL_DEBUG_MODE_TEST1, SHADER_DIR "/" "kernel_debug1_fp.cg.shd")) return false;
  if (!LoadVertexProgram  (KERNEL_DEBUG_MODE_WORK1, SHADER_DIR "/" "kernel_debug2_vp.cg.shd")) return false;
  if (!LoadFragmentProgram(KERNEL_DEBUG_MODE_WORK1, SHADER_DIR "/" "kernel_debug2_fp.cg.shd")) return false;

  return true;
}
Exemplo n.º 2
0
bool KernelBVTest::Prepare()
{
  ReserveSlots(KERNEL_BVTEST_MODE_COUNT);

  if (!LoadVertexProgram  (KERNEL_BVTEST_MODE_TEST, SHADER_DIR "/" "kernel_bvtest1_vp.cg.shd")) return false;
  if (!LoadFragmentProgram(KERNEL_BVTEST_MODE_TEST, SHADER_DIR "/" "kernel_bvtest1_fp.cg.shd")) return false;
  if (!LoadVertexProgram  (KERNEL_BVTEST_MODE_COMPUTATIONMASK, SHADER_DIR "/" "kernel_bvtest2_vp.cg.shd")) return false;
  if (!LoadFragmentProgram(KERNEL_BVTEST_MODE_COMPUTATIONMASK, SHADER_DIR "/" "kernel_bvtest2_fp.cg.shd")) return false;

  return true;
}
CSm3GroundDrawer::CSm3GroundDrawer(CSm3ReadMap *m)
{
	map = m;
	tr = map->renderer;
	rc = tr->AddRenderContext (&cam, true);

	tr->config.detailMod = configHandler.GetInt("SM3TerrainDetail", 200) / 100.0f;

	if (shadowHandler->drawShadows) {
		shadowrc = tr->AddRenderContext (&shadowCam,false);

		groundShadowVP=LoadVertexProgram("groundshadow.vp");
	}
	else  {
		shadowrc = 0;
		groundShadowVP = 0;
	}
	reflectrc = 0;
}
Exemplo n.º 4
0
void ModelDrawer::SetupGL()
{
	glewInitialized=true;

	GLenum err;
	if ((err=glewInit ()) != GLEW_OK) {
		fltk::message ("Failed to initialize GLEW: %s", glewGetErrorString (err));
	}
	else {
		canRenderS3O = 0;
		// see if S3O's can be rendered properly
		if (GLEW_ARB_multitexture && GLEW_ARB_texture_env_combine) {
			canRenderS3O = 1;
		} else
			fltk::message ("Basic S3O rendering is not possible with this graphics card");

		if (GLEW_ARB_fragment_program && GLEW_ARB_vertex_program && GLEW_ARB_texture_cube_map) {

			s3oFP = LoadFragmentProgram (applicationPath + "shaders/s3o.fp");
			s3oVP = LoadVertexProgram (applicationPath + "shaders/s3o.vp");
			s3oFPunlit = LoadFragmentProgram (applicationPath + "shaders/s3o_unlit.fp");
			s3oVPunlit = LoadVertexProgram (applicationPath + "shaders/s3o_unlit.vp");

			if (s3oFP && s3oVP && s3oFPunlit && s3oVPunlit) {
				canRenderS3O = 2;

				nv_dds::CDDSImage image;
				if (!image.load (applicationPath + "skybox.dds"))
				{
					fltk::message ("Failed to load skybox.dds");

					canRenderS3O=1;
				}

				glGenTextures (1, &skyboxTexture);
				glBindTexture (GL_TEXTURE_CUBE_MAP_ARB, skyboxTexture);
				if (!image.upload_textureCubemap ()) {
					glDeleteTextures(1,&skyboxTexture);
					skyboxTexture=0;
					fltk::message ("Can't upload cubemap texture skybox.dds");
					canRenderS3O=1;
				}
			} 
			else canRenderS3O=1;
		} else
			fltk::message ("Full S3O rendering is not possible with this graphics card, \nself-illumination and reflection won't be visible");
	}

	GLUquadricObj* sphere = gluNewQuadric ();
	gluQuadricNormals(sphere, GLU_NONE);

	sphereList=glGenLists (1);
	glNewList (sphereList, GL_COMPILE);
	gluSphere (sphere, 1.0f, 16, 8);
	glEndList ();

	gluDeleteQuadric (sphere);

	glGenTextures (1, &whiteTexture);
	glBindTexture (GL_TEXTURE_2D, whiteTexture);
	float pixel=1.0f;
	glTexImage2D (GL_TEXTURE_2D, 0, 3, 1,1,0,GL_LUMINANCE, GL_FLOAT, &pixel);
}
Exemplo n.º 5
0
/*
#define W_SIZE 4
#define WF_SIZE 4096
#define WH_SIZE 2048
*/
CDynWater::CDynWater(void)
{
	if (!FBO::IsSupported())
		throw content_error("DynWater Error: missing FBO support");

	lastWaveFrame=0;
	noWakeProjectiles=true;
	firstDraw=true;
	drawSolid=true;
	camPosBig=float3(2048,0,2048);
	refractSize=gu->viewSizeY>=1024 ? 1024:512;

	glGenTextures(1, &reflectTexture);
	glBindTexture(GL_TEXTURE_2D, reflectTexture);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8 ,512, 512, 0,GL_RGBA, GL_UNSIGNED_BYTE, 0);

	glGenTextures(1, &refractTexture);
	glBindTexture(GL_TEXTURE_2D, refractTexture);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8 ,refractSize, refractSize, 0,GL_RGBA, GL_UNSIGNED_BYTE, 0);

	glGenTextures(1, &detailNormalTex);
	glBindTexture(GL_TEXTURE_2D, detailNormalTex);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
	glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA16F_ARB ,256, 256, 0,GL_RGBA, GL_FLOAT, 0);
	glGenerateMipmapEXT(GL_TEXTURE_2D);

	float* temp=new float[1024*1024*4];

	for(int y=0;y<64;++y){
		for(int x=0;x<64;++x){
			temp[(y*64+x)*4+0]=(sin(x*PI*2.0f/64.0f)) + (x<32 ? -1:1)*0.3f;
			temp[(y*64+x)*4+1]=temp[(y*64+x)*4+0];
			temp[(y*64+x)*4+2]=(cos(x*PI*2.0f/64.0f)) + (x<32 ? 16-x:x-48)/16.0f*0.3f;
			temp[(y*64+x)*4+3]=0;
		}
	}
	glGenTextures(3, rawBumpTexture);
	glBindTexture(GL_TEXTURE_2D, rawBumpTexture[0]);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
	glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA16F_ARB ,64, 64, 0,GL_RGBA, GL_FLOAT, temp);

	CBitmap foam;
	if (!foam.Load(mapInfo->water.foamTexture))
		throw content_error("Could not load foam from file " + mapInfo->water.foamTexture);
	if (count_bits_set(foam.xsize)!=1 || count_bits_set(foam.ysize)!=1)
		throw content_error("Foam texture not power of two!");
	unsigned char* scrap=new unsigned char[foam.xsize*foam.ysize*4];
	for(int a=0;a<foam.xsize*foam.ysize;++a)
		scrap[a]=foam.mem[a*4];

	glGenTextures(1, &foamTex);
	glBindTexture(GL_TEXTURE_2D, foamTex);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
	glBuildMipmaps(GL_TEXTURE_2D, GL_LUMINANCE,foam.xsize,foam.ysize, GL_LUMINANCE, GL_UNSIGNED_BYTE, scrap);

	delete[] scrap;

	if(ProgramStringIsNative(GL_VERTEX_PROGRAM_ARB,"waterDyn.vp"))
		waterVP=LoadVertexProgram("waterDyn.vp");
	else
		waterVP=LoadVertexProgram("waterDynNT.vp");

	waterFP=LoadFragmentProgram("waterDyn.fp");
	waveFP=LoadFragmentProgram("waterDynWave.fp");
	waveVP=LoadVertexProgram("waterDynWave.vp");
	waveFP2=LoadFragmentProgram("waterDynWave2.fp");
	waveVP2=LoadVertexProgram("waterDynWave2.vp");
	waveNormalFP=LoadFragmentProgram("waterDynNormal.fp");
	waveNormalVP=LoadVertexProgram("waterDynNormal.vp");
	waveCopyHeightFP=LoadFragmentProgram("waterDynWave3.fp");
	waveCopyHeightVP=LoadVertexProgram("waterDynWave3.vp");
	dwGroundRefractVP=LoadVertexProgram("dwgroundrefract.vp");
	dwGroundReflectIVP=LoadVertexProgram("dwgroundreflectinverted.vp");
	dwDetailNormalFP=LoadFragmentProgram("dwDetailNormal.fp");
	dwDetailNormalVP=LoadVertexProgram("dwDetailNormal.vp");
	dwAddSplashFP=LoadFragmentProgram("dwAddSplash.fp");
	dwAddSplashVP=LoadVertexProgram("dwAddSplash.vp");

	waterSurfaceColor = mapInfo->water.surfaceColor;

	for(int y=0;y<1024;++y){
		for(int x=0;x<1024;++x){
			temp[(y*1024+x)*4+0]=0;
			temp[(y*1024+x)*4+1]=0;
			temp[(y*1024+x)*4+2]=0;
			temp[(y*1024+x)*4+3]=0;
		}
	}
	glGenTextures(1, &waveHeight32);
	glBindTexture(GL_TEXTURE_2D, waveHeight32);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
	glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA32F_ARB ,256, 256, 0,GL_RGBA, GL_FLOAT, temp);

	glGenTextures(1, &waveTex1);
	glBindTexture(GL_TEXTURE_2D, waveTex1);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
	glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA16F_ARB ,1024, 1024, 0,GL_RGBA, GL_FLOAT, temp);

	for(int y=0;y<1024;++y){
		for(int x=0;x<1024;++x){
			//float dist=(x-500)*(x-500)+(y-450)*(y-450);
			temp[(y*1024+x)*4+0]=0;//max(0.0f,15-sqrt(dist));//sin(y*PI*2.0f/64.0f)*0.5f+0.5f;
			temp[(y*1024+x)*4+1]=0;
			temp[(y*1024+x)*4+2]=0;
			temp[(y*1024+x)*4+3]=0;
		}
	}
	glGenTextures(1, &waveTex2);
	glBindTexture(GL_TEXTURE_2D, waveTex2);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
	glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA16F_ARB ,1024, 1024, 0,GL_RGBA, GL_FLOAT, temp);

	for(int y=0;y<1024;++y){
		for(int x=0;x<1024;++x){
			temp[(y*1024+x)*4+0]=0;
			temp[(y*1024+x)*4+1]=1;
			temp[(y*1024+x)*4+2]=0;
			temp[(y*1024+x)*4+3]=0;
		}
	}
	glGenTextures(1, &waveTex3);
	glBindTexture(GL_TEXTURE_2D, waveTex3);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
	glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA16F_ARB ,1024, 1024, 0,GL_RGBA, GL_FLOAT, temp);

	for(int y=0;y<64;++y){
		float dy=y-31.5f;
		for(int x=0;x<64;++x){
			float dx=x-31.5f;
			float dist=sqrt(dx*dx+dy*dy);
			temp[(y*64+x)*4+0]=std::max(0.0f,1-dist/30.f)*std::max(0.0f,1-dist/30.f);
			temp[(y*64+x)*4+1]=std::max(0.0f,1-dist/30.f);
			temp[(y*64+x)*4+2]=std::max(0.0f,1-dist/30.f)*std::max(0.0f,1-dist/30.f);
			temp[(y*64+x)*4+3]=0;
		}
	}

	glGenTextures(1, &splashTex);
	glBindTexture(GL_TEXTURE_2D, splashTex);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR/*_MIPMAP_NEAREST*/);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
	//gluBuild2DMipmaps(GL_TEXTURE_2D,GL_RGBA32F_ARB ,64, 64, GL_RGBA, GL_FLOAT, temp);
	glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA16F_ARB ,64, 64, 0,GL_RGBA, GL_FLOAT, temp);

	unsigned char temp2[]={0,0,0,0};
	glGenTextures(1, &zeroTex);
	glBindTexture(GL_TEXTURE_2D, zeroTex);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR/*_MIPMAP_NEAREST*/);
	glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA8 ,1, 1, 0,GL_RGBA, GL_UNSIGNED_BYTE, temp2);

	unsigned char temp3[]={0,255,0,0};
	glGenTextures(1, &fixedUpTex);
	glBindTexture(GL_TEXTURE_2D, fixedUpTex);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR/*_MIPMAP_NEAREST*/);
	glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA8 ,1, 1, 0,GL_RGBA, GL_UNSIGNED_BYTE, temp3);

	CBitmap bm;
	if (!bm.Load("bitmaps/boatshape.bmp"))
		throw content_error("Could not load boatshape from file bitmaps/boatshape.bmp");
	for(int a=0;a<bm.xsize*bm.ysize;++a){
		bm.mem[a*4+2]=bm.mem[a*4];
		bm.mem[a*4+3]=bm.mem[a*4];
	}
	boatShape=bm.CreateTexture();

	CBitmap bm2;
	if (!bm.Load("bitmaps/hovershape.bmp"))
		throw content_error("Could not load hovershape from file bitmaps/hovershape.bmp");
	for(int a=0;a<bm2.xsize*bm2.ysize;++a){
		bm2.mem[a*4+2]=bm2.mem[a*4];
		bm2.mem[a*4+3]=bm2.mem[a*4];
	}
	hoverShape=bm2.CreateTexture();

	delete[] temp;
	glGenFramebuffersEXT(1,&frameBuffer);

	reflectFBO.Bind();
	reflectFBO.AttachTexture(reflectTexture, GL_TEXTURE_2D, GL_COLOR_ATTACHMENT0_EXT);
	reflectFBO.CreateRenderBuffer(GL_DEPTH_ATTACHMENT_EXT, GL_DEPTH_COMPONENT32, 512, 512);
	refractFBO.Bind();
	refractFBO.AttachTexture(refractTexture, GL_TEXTURE_2D, GL_COLOR_ATTACHMENT0_EXT);
	refractFBO.CreateRenderBuffer(GL_DEPTH_ATTACHMENT_EXT, GL_DEPTH_COMPONENT32, refractSize, refractSize);
	FBO::Unbind();

	if (!reflectFBO.IsValid() || !refractFBO.IsValid())
		throw content_error("DynWater Error: Invalid FBO");
}