コード例 #1
0
ファイル: Client.cpp プロジェクト: mgerhardy/engine
// TODO: generate bigger buffers and use glBufferSubData
video::GLMeshData Client::createMesh(voxel::DecodedMesh& surfaceMesh, const glm::ivec2& translation, float scale) {
	// Convenient access to the vertices and indices
	const uint32_t* vecIndices = surfaceMesh.getRawIndexData();
	const uint32_t numIndices = surfaceMesh.getNoOfIndices();
	const voxel::VoxelVertexDecoded* vecVertices = surfaceMesh.getRawVertexData();
	const uint32_t numVertices = surfaceMesh.getNoOfVertices();

	// This struct holds the OpenGL properties (buffer handles, etc) which will be used
	// to render our mesh. We copy the data from the PolyVox mesh into this structure.
	video::GLMeshData meshData;

	// Create the VAO for the mesh
	glGenVertexArrays(1, &meshData.vertexArrayObject);
	core_assert(meshData.vertexArrayObject > 0);
	glBindVertexArray(meshData.vertexArrayObject);

	// The GL_ARRAY_BUFFER will contain the list of vertex positions
	glGenBuffers(1, &meshData.vertexBuffer);
	core_assert(meshData.vertexBuffer > 0);
	glBindBuffer(GL_ARRAY_BUFFER, meshData.vertexBuffer);
	glBufferData(GL_ARRAY_BUFFER, numVertices * sizeof(voxel::VoxelVertexDecoded), vecVertices, GL_STATIC_DRAW);

	// and GL_ELEMENT_ARRAY_BUFFER will contain the indices
	glGenBuffers(1, &meshData.indexBuffer);
	core_assert(meshData.indexBuffer > 0);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, meshData.indexBuffer);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, numIndices * sizeof(typename voxel::DecodedMesh::IndexType), vecIndices, GL_STATIC_DRAW);

	const int posLoc = _worldShader.enableVertexAttribute("a_pos");
	glVertexAttribPointer(posLoc, 3, GL_FLOAT, GL_FALSE, sizeof(voxel::VoxelVertexDecoded),
			GL_OFFSET(offsetof(voxel::VoxelVertexDecoded, position)));

	const int matLoc = _worldShader.enableVertexAttribute("a_materialdensity");
	// our material and density is encoded as 8 bits material and 8 bits density
	core_assert(sizeof(voxel::Voxel) == sizeof(uint16_t));
	glVertexAttribIPointer(matLoc, sizeof(voxel::Voxel), GL_UNSIGNED_BYTE, sizeof(voxel::VoxelVertexDecoded),
			GL_OFFSET(offsetof(voxel::VoxelVertexDecoded, data)));

	glBindVertexArray(0);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
	glBindBuffer(GL_ARRAY_BUFFER, 0);

	Log::trace("mesh information:\n- mesh indices: %i, vertices: %i\n- position: %i:%i", numIndices, numVertices, translation.x,
			translation.y);

	meshData.noOfIndices = numIndices;
	meshData.translation = translation;
	meshData.scale = scale;
	meshData.indexType = GL_UNSIGNED_INT;
	return meshData;
}
コード例 #2
0
void ceProgramParameterGL20::Bind(int size, int stride, unsigned offset, ceDataType type)
{
	assert (_type == PPT_Attribute);
	assert (_location != -1);
	GLenum t = convert_data_type_to_gl_enum(type);
	glVertexAttribPointer (_location, size, t, false, stride, GL_OFFSET(offset));
}
コード例 #3
0
ファイル: ui_renderer_gl.cpp プロジェクト: mgerhardy/engine
void UIRendererGL::RenderBatch(Batch *batch) {
    BindBitmap(batch->bitmap);
    if (g_current_batch != batch) {
        g_current_batch = batch;
    }
    glBindBuffer(GL_ARRAY_BUFFER, _buffer);
    glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * batch->vertex_count, batch->vertex, GL_STATIC_DRAW);
    glVertexAttribPointer(_shader.enableVertexAttribute("a_color"), 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(Vertex), GL_OFFSET(offsetof(Batch, vertex[0].col)));
    glVertexAttribPointer(_shader.enableVertexAttribute("a_texcoord"), 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), GL_OFFSET(offsetof(Batch, vertex[0].u)));
    glVertexAttribPointer(_shader.enableVertexAttribute("a_pos"), 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), GL_OFFSET(offsetof(Batch, vertex[0].x)));

    glDrawArrays(GL_TRIANGLES, 0, batch->vertex_count);
    GL_checkError();
}
コード例 #4
0
ファイル: Client.cpp プロジェクト: mgerhardy/engine
core::AppState Client::onInit() {
	eventBus()->subscribe<network::NewConnectionEvent>(*this);
	eventBus()->subscribe<network::DisconnectEvent>(*this);
	eventBus()->subscribe<voxel::WorldCreatedEvent>(*this);

	GLDebug::enable(GLDebug::Medium);

	core::AppState state = UIApp::onInit();
	if (state != core::Running)
		return state;

	if (!_network->start())
		return core::Cleanup;

	core::Var::get(cfg::ClientName, "noname");
	core::Var::get(cfg::ClientPassword, "nopassword");

	if (!_worldShader.init()) {
		return core::Cleanup;
	}
	if (!_meshShader->init()) {
		return core::Cleanup;
	}
	if (!_waterShader->init()) {
		return core::Cleanup;
	}

	_waterTexture = video::TexturePtr(new video::Texture("texture/water.png"));
	_waterTexture->load();
	const glm::vec3 vertices[4] = { glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(1.0f,
			1.0f, 0.0f) };
	const glm::ivec3 indices[2] = { glm::ivec3( 0, 1, 2 ), glm::ivec3( 1, 3, 2 ) };
	glGenVertexArrays(1, &_waterData.vertexArrayObject);
	core_assert(_waterData.vertexArrayObject > 0);
	glBindVertexArray(_waterData.vertexArrayObject);

	glGenBuffers(1, &_waterData.vertexBuffer);
	core_assert(_waterData.vertexBuffer > 0);
	glBindBuffer(GL_ARRAY_BUFFER, _waterData.vertexBuffer);
	glBufferData(GL_ARRAY_BUFFER, 4 * sizeof(glm::vec3), vertices, GL_STATIC_DRAW);

	glGenBuffers(1, &_waterData.indexBuffer);
	core_assert(_waterData.indexBuffer > 0);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _waterData.indexBuffer);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, 2 * sizeof(glm::ivec2), indices, GL_STATIC_DRAW);

	const int posLoc = _waterShader->enableVertexAttribute("a_pos");
	glVertexAttribPointer(posLoc, 3, GL_FLOAT, GL_FALSE, sizeof(voxel::VoxelVertexDecoded),
			GL_OFFSET(offsetof(voxel::VoxelVertexDecoded, position)));

	glBindVertexArray(0);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
	glBindBuffer(GL_ARRAY_BUFFER, 0);

	_waterData.noOfIndices = 2;
	_waterData.scale = 1.0f;
	_waterData.indexType = GL_UNSIGNED_INT;

	GL_checkError();

	_camera.init(_width, _height);

	registerMoveCmd("+move_right", MOVERIGHT);
	registerMoveCmd("+move_left", MOVELEFT);
	registerMoveCmd("+move_forward", MOVEFORWARD);
	registerMoveCmd("+move_backward", MOVEBACKWARD);

	const int ColorTextureSize = 256;
	uint8_t colorTexture[ColorTextureSize * ColorTextureSize * 3];
	noise::Simplex::SeamlessNoise2DRGB(colorTexture, ColorTextureSize, 3, 0.3f, 0.7f);
	_colorTexture = video::TexturePtr(new video::Texture(colorTexture, ColorTextureSize, ColorTextureSize, 3));

	_clearColor = glm::vec3(0.0, 0.6, 0.796);

	_root.SetSkinBg(TBIDC("background"));
	new frontend::LoginWindow(this);

	SDL_GL_SetSwapInterval(core::Var::get(cfg::ClientVSync, "false")->boolVal());

	return state;
}