コード例 #1
0
	/**
	 * default constructor
	 */
	CGlDrawFlatCubeMap()
	{
		program.initVertFragShadersFromDirectory("draw/flat_cube_map");
		if (program.error())
		{
			std::cerr << program.error.getString() << std::endl;
			return;
		}
		program.bindAttribLocation(0, "vertex_position");

		program.link();
		if (program.error())
		{
			std::string infoLog;
			program.getInfoLog(infoLog);
			std::cerr << "info Log: linking: " << infoLog << std::endl;
			return;
		}

		program.bindAttribLocation(0, "vertex_position");
		program.bindAttribLocation(1, "vertex_texture_coord");

		program.setupUniform(pvm_matrix_uniform, "pvm_matrix");

		static const float vertices[4][4] = {
					{-1.0, -1.0, 0.0, 1.0},
					{ 1.0, -1.0, 0.0, 1.0},
					{-1.0,  1.0, 0.0, 1.0},
					{ 1.0,  1.0, 0.0, 1.0},
				};

		const float N = -1;
		const float P = 1;
		static const float texcoords[6][4][3] = {
				{	{P, N, N},	{P, N, P},	{P, P, N},	{P, P, P}	},	// X pos
				{	{N, N, P},	{N, N, N},	{N, P, P},	{N, P, N}	},	// X neg
				{	{N, P, N},	{P, P, N},	{N, P, P},	{P, P, P}	},	// Y pos
				{	{N, N, P},	{P, N, P},	{N, N, N},	{P, N, N}	},	// Y neg
				{	{P, N, P},	{N, N, P},	{P, P, P},	{N, P, P}	},	// Z pos
				{	{N, N, N},	{P, N, N},	{N, P, N},	{P, P, N}	},	// Z neg
		};

		vao.bind();

			buffer.bind();
			buffer.resize(sizeof(vertices)+sizeof(texcoords));

			buffer.subData(0, sizeof(vertices), vertices);
			glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
			glEnableVertexAttribArray(0);

			buffer.subData(sizeof(vertices), sizeof(texcoords), texcoords);
			glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*)sizeof(vertices));
			glEnableVertexAttribArray(1);

		vao.unbind();
	}
コード例 #2
0
ファイル: GlDrawSkyBox.hpp プロジェクト: schreiberx/sweet
	CGlDrawSkyBox()	:
			vertex_buffer(GL_ARRAY_BUFFER),
			index_buffer(GL_ELEMENT_ARRAY_BUFFER),
			texture_cube_map(GL_TEXTURE_CUBE_MAP)
	{
		program.initVertFragShadersFromDirectory("draw/skybox");
		CError_AppendReturn(program);

		program.link();
		if (program.error())
		{
			std::cerr << "info Log: linking: " << program.getInfoLog() << std::endl;
			return;
		}

		program.setupUniform(pvm_matrix_uniform, "pvm_matrix");
		program.use();
		program.setUniform1i("sampler_cube", 0);
		program.disable();

		/**
		 * initialize buffers
		 */
		/*
		 * vertices for cube drawn counterclockwise
		 * use quads to draw surfaces
		 */
#define P	+1.0f
#define N	-1.0f
		static const GLfloat vertices[8][3] = {
				{N,N,P},
				{N,N,N},
				{N,P,P},
				{N,P,N},
				{P,N,P},
				{P,N,N},
				{P,P,P},
				{P,P,N},
			};

#undef N
#undef P
#if 0
		static const GLubyte indices[20] = {
#if 0
				// faces for counter clockwise triangle strips
				4,6,0,2,	// front
				1,3,		// left
				5,7,		// back
				4,6,		// right
				6,			// > ZERO triangle
				7,2,3,		// top
				3,1,		// > ZERO triangle
				1,5,0,4		// bottom
#else
				// faces for clockwise triangle strips
				6,4,2,0,	// front
				3,1,		// left
				7,5,		// back
				6,4,		// right
				4,			// > ZERO triangle
				5,0,1,		// bottom
				1,3,		// > ZERO triangle
				3,7,2,6,		// top
#endif
		};
#else
		static const GLubyte indices[20] = {
#if 0
				// faces for counter clockwise triangle strips
				4,6,0,2,	// front
				1,3,		// left
				5,7,		// back
				4,6,		// right
				6,			// > ZERO triangle
				7,2,3,		// top
				3,1,		// > ZERO triangle
				1,5,0,4		// bottom
#else
				// faces for clockwise triangle strips
				6,4,2,0,	// front
				3,1,		// left
				7,5,		// back
				6,4,		// right
				4,			// > ZERO triangle
				5,0,1,		// bottom
				1,3,		// > ZERO triangle
				3,7,2,6,		// top
#endif
		};
#endif
		vertex_buffer.bind();
		vertex_buffer.data(sizeof(vertices), vertices);
		vertex_buffer.unbind();

		index_buffer.bind();
		index_buffer.data(sizeof(indices), indices);
		index_buffer.unbind();
	}