コード例 #1
0
void CGLBase::SetImage(void)
{
	char buf1[100];
	char *files1[1];

	sprintf_s(buf1, "images/ball128.jpg");
	*files1 = buf1;
	BOOL genTexture1 = GenerateTextures(files1, &m_TextureId1,1);
	DWORD er1 = GetLastError();
	
	char buf2[100];
	char *files2[1];

	sprintf_s(buf2, "images/windows128.jpg");
	*files2 = buf2;
	BOOL genTexture2 = GenerateTextures(files2, &m_TextureId2,1);
	DWORD er2 = GetLastError();
	
	char buf3[100];
	char *files3[1];

	sprintf_s(buf3, "images/round128.jpg");
	*files3 = buf3;
	BOOL genTexture3 = GenerateTextures(files3, &m_TextureId3,1);
	DWORD er3 = GetLastError();
	
    glBindTexture(GL_TEXTURE_2D, NULL);

	 
}
コード例 #2
0
ファイル: chess.c プロジェクト: AlexGreulich/HRTFVR
void init_textures(void)
{
#if !defined(USE_DISPLAY_LISTS)
    glGenTextures(3, texName);
#else
    texName[0] = 1000;
    texName[1] = 1001;
    texName[2] = 1002;
#endif
    GenerateTextures();
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

#if !defined(USE_DISPLAY_LISTS)
    glBindTexture(GL_TEXTURE_2D, texName[0]);
#else
    glNewList(texName[0], GL_COMPILE);
#endif
    glTexImage2D(GL_TEXTURE_2D, 0, 3, TXSX, TXSY, 0, GL_RGB,
	GL_UNSIGNED_BYTE, &wood[0][0][0]);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
#if defined(USE_DISPLAY_LISTS)
    glEndList();
#endif

#if !defined(USE_DISPLAY_LISTS)
    glBindTexture(GL_TEXTURE_2D, texName[1]);
#else
    glNewList(texName[1], GL_COMPILE);
#endif
    glTexImage2D(GL_TEXTURE_2D, 0, 3, TXSX, TXSY, 0, GL_RGB,
	GL_UNSIGNED_BYTE, &white_square[0][0][0]);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
#if defined(USE_DISPLAY_LISTS)
    glEndList();
#endif

#if !defined(USE_DISPLAY_LISTS)
    glBindTexture(GL_TEXTURE_2D, texName[2]);
#else
    glNewList(texName[2], GL_COMPILE);
#endif
    glTexImage2D(GL_TEXTURE_2D, 0, 3, TXSX, TXSY, 0, GL_RGB,
	GL_UNSIGNED_BYTE, &black_square[0][0][0]);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
#if defined(USE_DISPLAY_LISTS)
    glEndList();
#endif
}
コード例 #3
0
UObject* UHGGifFactory::FactoryCreateBinary
(
	UClass*				Class,
	UObject*			InParent,
	FName				Name,
	EObjectFlags		Flags,
	UObject*			Context,
	const TCHAR*		Type,
	const uint8*&		Buffer,
	const uint8*		BufferEnd,
	FFeedbackContext*	Warn
	)
{
	check(Type);

	if (GenerateConverterDll() == false)
	{
		return nullptr;
	}

	// 1. Copy Gif File to Buffer
	const int32 Length = BufferEnd - Buffer;
	TArray<uint8> GifBytes;
	GifBytes.AddUninitialized(Length);	// Allocate Empty Space
	
	FMemory::Memcpy(GifBytes.GetData(), Buffer, Length);

	// 2. Decode Gif File using Gifconverter.dll
	TArray<FBinaryImage> BinaryImages;
	DecodeGifFile(GifBytes, BinaryImages);

	// 3. Convert to Texture2D from Decoded Binary Images
	TArray<UTexture2D*> GifFrameTextures;
	GifFrameTextures.Empty(BinaryImages.Num());
	GenerateTextures(BinaryImages, GifFrameTextures, InParent, Name, Type, Flags, Context, Warn);

	// 4. Create PaperSprite From GifFrame Texture2D
	TArray<UPaperSprite*> Sprites;
	Sprites.Empty(GifFrameTextures.Num());
	GenerateSprites(GifFrameTextures, Sprites, InParent, Flags, Context, Warn);

	// 5. Create PaperBook
	UPaperFlipbook* NewFlipbook = CreateFlipBook(Sprites, Name);

	// 6. Free Allocated Memory
	CleanUpFactory(BinaryImages);

	return NewFlipbook;
}
コード例 #4
0
ファイル: CgShaderCel.cpp プロジェクト: ttvd/cg-shaders
	//--
	CgShaderCel::CgShaderCel(CGcontext cgContext) : 
		CgShader(cgContext, CgShader::VertexFragment)
	{
		// [rad] This is vertex and fragment shader
	
		// [rad] Setup vertex shader:
		
		// [rad] Setup vertex shader entry point
		SetEntry(CgShader::Vertex, "main");

		static const std::string sProgramVertex = "							\
																			\
		void main(	float4 inPosition			: POSITION,					\
					float4 inNormal				: NORMAL,					\
																			\
					out float4 outOPosition		: POSITION,					\
					out float4 outVPosition		: TEXCOORD0,				\
					out float4 outNormal		: TEXCOORD1,				\
																			\
					uniform float4x4 uniModelViewProjMat,					\
					uniform float4x4 uniModelViewITMat,						\
					uniform float4x4 uniModelViewMat)						\
		{																	\
			outOPosition = mul(uniModelViewProjMat, inPosition);			\
			outVPosition = mul(uniModelViewMat, inPosition);				\
																			\
			outNormal = mul(uniModelViewITMat, inNormal);					\
			outNormal.xyz = normalize(outNormal.xyz);						\
		}																	";
		
		// [rad] Setup vertex shader program
		SetProgram(CgShader::Vertex, sProgramVertex);
		
		// [rad] Setup fragment shader:
		
		// [rad] Setup fragment shader entry point
		SetEntry(CgShader::Fragment, "main");
		
		static const std::string sProgramFragment = "						\
																			\
		void main(															\
					float4 inPosition					: TEXCOORD0,		\
					float4 inNormal						: TEXCOORD1,		\
																			\
					out float4 outColor					: COLOR,			\
																			\
					uniform sampler1D uniTexDiffuse,						\
					uniform sampler1D uniTexSpecular,						\
					uniform sampler1D uniTexOutline,						\
																			\
					uniform float3 uniMatDiffuse,							\
					uniform float3 uniMatSpecular,							\
					uniform float3 uniLightColor,							\
					uniform float3 uniLightPosition,						\
					uniform float3 uniEyePosition,							\
					uniform float uniShininess,								\
																			\
					uniform int uniComputeOutline)							\
		{																	\
																			\
			float3 p = inPosition.xyz;										\
			float3 n = normalize(inNormal.xyz);								\
																			\
			float3 l = normalize(uniLightPosition - p);						\
			float diffuseL = max(dot(n, l), 0);								\
			diffuseL = tex1D(uniTexDiffuse, diffuseL).x;					\
			float3 diffuse = uniLightColor * diffuseL * uniMatDiffuse;		\
																			\
			float3 v = normalize(uniEyePosition - p);						\
			float3 h = normalize(l + v);									\
			float specularL = pow(max(dot(n, h), 0), uniShininess);			\
			if(diffuseL <= 0) specularL = 0;								\
			specularL = tex1D(uniTexSpecular, specularL).x;					\
			float3 specular = uniLightColor * specularL * uniMatSpecular;	\
																			\
			float edgeL = 1;												\
																			\
			if(uniComputeOutline)											\
			{																\
				edgeL = max(dot(n, v), 0);									\
				edgeL = tex1D(uniTexOutline, edgeL).x;						\
			}																\
																			\
			outColor.x = edgeL * (diffuse + specular);						\
			outColor.y = edgeL * (diffuse + specular);						\
			outColor.z = edgeL * (diffuse + specular);						\
			outColor.w = 1;													\
		}																	";

		// float3 diffuse = diffuseL * uniMatDiffuse;
		// float3 specular = specularL * uniMatSpecular;
		
		// [rad] Setup fragment shader program
		SetProgram(CgShader::Fragment, sProgramFragment);
		
		// [rad] Create shaders (both fragment and vertex)
		Create();
		
		// [rad] Set params - vertex shader
		m_cgParamModelViewProjMatrix = cgGetNamedParameter(m_cgShaderVertex, "uniModelViewProjMat");
		m_cgParamModelViewMatrix = cgGetNamedParameter(m_cgShaderVertex, "uniModelViewMat");
		m_cgParamModelViewITMatrix = cgGetNamedParameter(m_cgShaderVertex, "uniModelViewITMat");
		
		// [rad] Set params - fragment shader				
		m_cgParamLightColorVector = cgGetNamedParameter(m_cgShaderFragment, "uniLightColor");
		m_cgParamLightPositionVector = cgGetNamedParameter(m_cgShaderFragment, "uniLightPosition");	
		
		m_cgParamEyePositionVector = cgGetNamedParameter(m_cgShaderFragment, "uniEyePosition");	
		
		m_cgParamShininess = cgGetNamedParameter(m_cgShaderFragment, "uniShininess");	
		
		m_cgParamMatDiffuseVector = cgGetNamedParameter(m_cgShaderFragment, "uniMatDiffuse");	
		m_cgParamMatSpecularVector = cgGetNamedParameter(m_cgShaderFragment, "uniMatSpecular");
		
		m_cgParamSamplerDiffuse = cgGetNamedParameter(m_cgShaderFragment, "uniTexDiffuse");	
		m_cgParamSamplerSpecular = cgGetNamedParameter(m_cgShaderFragment, "uniTexSpecular");	
		m_cgParamSamplerOutline = cgGetNamedParameter(m_cgShaderFragment, "uniTexOutline");	
		
		m_cgParamComputeOutline = cgGetNamedParameter(m_cgShaderFragment, "uniComputeOutline");	
		
		// [rad] Manually assign other (material) related params
		cgSetParameter1f(m_cgParamShininess, 128.0f);
	
		static const float af3ColorDiffuse[3] = {0.8f, 0.8f, 0.8f};
		cgSetParameter3fv(m_cgParamMatDiffuseVector, af3ColorDiffuse); 
		
		static const float af3ColorSpecular[3] = {1.0f, 1.0f, 1.0f};
		cgSetParameter3fv(m_cgParamMatSpecularVector, af3ColorSpecular);
		
		static const float af3Color[3] = {1.0f, 1.0f, 1.0f};
		cgSetParameter3fv(m_cgParamLightColorVector, af3Color);
		
		// [rad] Set texture params
		GenerateTextures();
		
		cgGLSetTextureParameter(m_cgParamSamplerDiffuse, m_glIDTextureDiffuse);
		cgGLSetTextureParameter(m_cgParamSamplerSpecular, m_glIDTextureSpecular);
		cgGLSetTextureParameter(m_cgParamSamplerOutline, m_glIDTextureOutline);
		
	}
コード例 #5
0
int main(int argc, char *argv[])
{
	// inicjalizacja biblioteki GLUT
	glutInit(&argc, argv);

	// inicjalizacja bufora ramki
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);

	// rozmiary głównego okna programu
	glutInitWindowSize(550, 550);

	// utworzenie głównego okna programu
	glutCreateWindow("Zadanie 1");

	// dołączenie funkcji generującej scenę 3D
	glutDisplayFunc(DisplayScene);

	// dołączenie funkcji wywoływanej przy zmianie rozmiaru okna
	glutReshapeFunc(Reshape);

	// utworzenie podmenu - Tekstura
	int MenuTexture = glutCreateMenu(Menu);
	glutAddMenuEntry("white_skin_guy_black_hairs.tga (kompresja)", TEXTURE_LENA);
	glutAddMenuEntry("white_skin_guy_black_hairs.tga (bez kompresji)", TEXTURE_LENA_UNC);
	glutAddMenuEntry("white_skin_guy_black_hairs_gray.tga (kompresja)", TEXTURE_LENA_GRAY);
	glutAddMenuEntry("white_skin_guy_black_hairs_gray.tga (bez kompresji)", TEXTURE_LENA_GRAY_UNC);

	// utworzenie podmenu - GL_TEXTURE_COMPRESSION_HINT
	int MenuTextureCompressionHint = glutCreateMenu(Menu);
	glutAddMenuEntry("GL_FASTEST", TEXTURE_COMPRESSION_FASTEST);
	glutAddMenuEntry("GL_DONT_CARE", TEXTURE_COMPRESSION_DONT_CARE);
	glutAddMenuEntry("GL_NICEST", TEXTURE_COMPRESSION_NICEST);

	// utworzenie podmenu - Aspekt obrazu
	int MenuAspect = glutCreateMenu(Menu);
#ifdef WIN32

	glutAddMenuEntry("Aspekt obrazu - całe okno", FULL_WINDOW);
#else

	glutAddMenuEntry("Aspekt obrazu - cale okno", FULL_WINDOW);
#endif

	glutAddMenuEntry("Aspekt obrazu 1:1", ASPECT_1_1);

	// menu główne
	glutCreateMenu(Menu);
	glutAddSubMenu("Tekstura", MenuTexture);
	glutAddSubMenu("GL_TEXTURE_COMPRESSION_HINT", MenuTextureCompressionHint);
	glutAddSubMenu("Aspekt obrazu", MenuAspect);

#ifdef WIN32

	glutAddMenuEntry("Wyjście", EXIT);
#else

	glutAddMenuEntry("Wyjscie", EXIT);
#endif

	// określenie przycisku myszki obsługującego menu podręczne
	glutAttachMenu(GLUT_RIGHT_BUTTON);

	// utworzenie tekstur
	GenerateTextures();

	// sprawdzenie i przygotowanie obsługi wybranych rozszerzeń
	ExtensionSetup();

	// wprowadzenie programu do obsługi pętli komunikatów
	glutMainLoop();
	return 0;
}
コード例 #6
0
void Menu(int value)
{
	GLint tmp_texture;
	switch (value)
	{
		// kompresja tekstur - GL_FASTEST
	case TEXTURE_COMPRESSION_FASTEST:
	{
										texture_compression_hint = GL_FASTEST;
										tmp_texture = texture;
										GenerateTextures();
										texture = tmp_texture;
										DisplayScene();
	}
		break;

		// kompresja tekstur - GL_DONT_CARE
	case TEXTURE_COMPRESSION_DONT_CARE:
	{
										  texture_compression_hint = GL_DONT_CARE;
										  tmp_texture = texture;
										  GenerateTextures();
										  texture = tmp_texture;
										  DisplayScene();
	}
		break;

		// kompresja tekstur - GL_NICEST
	case TEXTURE_COMPRESSION_NICEST:
	{
									   texture_compression_hint = GL_NICEST;
									   tmp_texture = texture;
									   GenerateTextures();
									   texture = tmp_texture;
									   DisplayScene();
	}
		break;

		// tekstura white_skin_guy_black_hairs
	case TEXTURE_LENA:
	{
						 texture = LENA;
						 DisplayScene();
	}
		break;

		// teksura white_skin_guy_black_hairs nieskompresowana
	case TEXTURE_LENA_UNC:
	{
							 texture = LENA_UNC;
							 DisplayScene();
	}
		break;

		// tekstura white_skin_guy_black_hairs_gray
	case TEXTURE_LENA_GRAY:
	{
							  texture = LENA_GRAY;
							  DisplayScene();
	}
		break;

		// tekstura white_skin_guy_black_hairs_gray nieskompresowana
	case TEXTURE_LENA_GRAY_UNC:
	{
								  texture = LENA_GRAY_UNC;
								  DisplayScene();
	}
		break;

		// obszar renderingu - całe okno
	case FULL_WINDOW:
	{
						aspect = FULL_WINDOW;
						Reshape(glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT));
	}
		break;

		// obszar renderingu - aspekt 1:1
	case ASPECT_1_1:
	{
					   aspect = ASPECT_1_1;
					   Reshape(glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT));
	}
		break;

		// wyjście
	case EXIT:
		exit(0);
	}
}
コード例 #7
0
ファイル: 3-zad3.cpp プロジェクト: DamianS1994/GRAFIKA
int main(int argc, char *argv[])
{
	// inicjalizacja biblioteki GLUT
	glutInit(&argc, argv);

	// inicjalizacja bufora ramki
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);

	// rozmiary głównego okna programu
	glutInitWindowSize(500, 500);

	// utworzenie głównego okna programu
	glutCreateWindow("Zadanie 3");

	// dołączenie funkcji generującej scenę 3D
	glutDisplayFunc(DisplayScene);

	// dołączenie funkcji wywoływanej przy zmianie rozmiaru okna
	glutReshapeFunc(Reshape);

	// dołączenie funkcji obsługi klawiatury
	glutKeyboardFunc(Keyboard);

	// obsługa przycisków myszki
	glutMouseFunc(MouseButton);

	// obsługa ruchu kursora myszki
	glutMotionFunc(MouseMotion);

	// utworzenie podmenu - Planeta
	int MenuPlanet = glutCreateMenu(Menu);
	glutAddMenuEntry("Wenus", VENUS_TEX);
	glutAddMenuEntry("Ziemia", EARTH_TEX);
	glutAddMenuEntry("Mars", MARS_TEX);
	glutAddMenuEntry("Jowisz", JUPITER_TEX);

	// utworzenie podmenu - Filtr pomniejszający
	int MenuMinFilter = glutCreateMenu(Menu);
	glutAddMenuEntry("GL_NEAREST_MIPMAP_NEAREST", GL_NEAREST_MIPMAP_NEAREST);
	glutAddMenuEntry("GL_NEAREST_MIPMAP_LINEAR", GL_NEAREST_MIPMAP_LINEAR);
	glutAddMenuEntry("GL_LINEAR_MIPMAP_NEAREST", GL_LINEAR_MIPMAP_NEAREST);
	glutAddMenuEntry("GL_LINEAR_MIPMAP_LINEAR", GL_LINEAR_MIPMAP_LINEAR);

	// utworzenie podmenu - Aspekt obrazu
	int MenuAspect = glutCreateMenu(Menu);
#ifdef WIN32

	glutAddMenuEntry("Aspekt obrazu - całe okno", FULL_WINDOW);
#else

	glutAddMenuEntry("Aspekt obrazu - cale okno", FULL_WINDOW);
#endif

	glutAddMenuEntry("Aspekt obrazu 1:1", ASPECT_1_1);

	// menu główne
	glutCreateMenu(Menu);
	glutAddSubMenu("Planeta", MenuPlanet);

#ifdef WIN32

	glutAddSubMenu("Filtr pomniejszający", MenuMinFilter);
	glutAddSubMenu("Aspekt obrazu", MenuAspect);
	glutAddMenuEntry("Wyjście", EXIT);
#else

	glutAddSubMenu("Filtr pomniejszajacy", MenuMinFilter);
	glutAddSubMenu("Aspekt obrazu", MenuAspect);
	glutAddMenuEntry("Wyjscie", EXIT);
#endif

	// określenie przycisku myszki obsługującego menu podręczne
	glutAttachMenu(GLUT_RIGHT_BUTTON);

	// utworzenie tekstur
	GenerateTextures();

	// sprawdzenie i przygotowanie obsługi wybranych rozszerzeñ
	ExtensionSetup();

	// wprowadzenie programu do obsługi pętli komunikatów
	glutMainLoop();
	return 0;
}