コード例 #1
0
ファイル: GlDrawSkyBox.hpp プロジェクト: schreiberx/sweet
	/**
	 * render skybox
	 */
	void renderWithProgram(GLSL::mat4 &p_pvm_matrix)
	{
//		CGlStateDisable depth_test(GL_DEPTH_TEST);
CGlErrorCheck();
		program.use();
		pvm_matrix_uniform.set(p_pvm_matrix);

		vertex_buffer.bind();
		glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
		glEnableVertexAttribArray(0);
		texture_cube_map.bind();

#if 0
		CGlErrorCheck();
		glDrawArrays(GL_TRIANGLES, 0, 3);
		CGlErrorCheck();
#else
		index_buffer.bind();
		CGlErrorCheck();
		glDrawElements(GL_TRIANGLE_STRIP, 20, GL_UNSIGNED_BYTE, 0);
		index_buffer.unbind();
#endif

		texture_cube_map.unbind();
		glDisableVertexAttribArray(0);
		vertex_buffer.unbind();
		program.disable();
		CGlErrorCheck();
	}
コード例 #2
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();
	}
コード例 #3
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();
	}
コード例 #4
0
ファイル: GlProgram.hpp プロジェクト: pedrospeixoto/sweet
	/**
	 * activate usage of program in current program block {}
	 */
	inline GlProgramUse(GlProgram &p_program)
	{
		p_program.use();
	}
コード例 #5
0
	/**
	 * render flat cube map
	 */
	void render(	CGlCubeMap &cGlCubeMap,	///< handler to cube map
					float scale = 1.0f		///< scale flat cube map with this factor
	)
	{

		cGlCubeMap.texture_cube_map.bind();

		CGlViewport cGlViewport;
		cGlViewport.saveState();

		GLSL::mat4 pmv = GLSL::ortho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f);
		program.use();
		pvm_matrix_uniform.set(pmv);

		vao.bind();
		CGlErrorCheck();

		pmv = GLSL::ortho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f);

// line in texture coordinates (offset = vertices)
#define TEX_LINE(l)		(sizeof(GLfloat)*4*4 + (l)*4*3*sizeof(GLfloat))

		buffer.bind();
		// LEFT
		glViewport(0*scale, cGlCubeMap.depth*scale, cGlCubeMap.depth*scale, cGlCubeMap.height*scale);
		glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*)TEX_LINE(1));
		glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

		// FRONT
		glViewport(cGlCubeMap.depth*scale, cGlCubeMap.depth*scale, cGlCubeMap.width*scale, cGlCubeMap.height*scale);
		glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*)TEX_LINE(5));
		glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

		// RIGHT
		glViewport(cGlCubeMap.depth*scale+cGlCubeMap.width*scale, cGlCubeMap.depth*scale, cGlCubeMap.depth*scale, cGlCubeMap.height*scale);
		glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*)TEX_LINE(0));
		glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

		// BACK
		glViewport(cGlCubeMap.depth*2*scale+cGlCubeMap.width*scale, cGlCubeMap.depth*scale, cGlCubeMap.width*scale, cGlCubeMap.height*scale);
		glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*)TEX_LINE(4));
		glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

		// BOTTOM
		glViewport(cGlCubeMap.depth*scale, 0, cGlCubeMap.width*scale, cGlCubeMap.depth*scale);
		glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*)TEX_LINE(3));
		glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

		// TOP
		glViewport(cGlCubeMap.depth*scale, cGlCubeMap.depth*scale + cGlCubeMap.height*scale, cGlCubeMap.width*scale, cGlCubeMap.depth*scale);
		glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*)TEX_LINE(2));
		glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

		cGlViewport.restoreState();

		vao.unbind();

		program.disable();

		CGlErrorCheck();

		glFlush();
	}