History

Working on support for a textured face mode that doesn't rely on the video stream.

Andrzej Kapolka committed 13 years ago

Commit 720ae561 parent e5de6719 files · +390 −184Browse files

Showing the changes to interface/src/VoxelSystem.cpp (1 of 9 files). Show all

Unified · Split

interface/src/VoxelSystem.cpp+3−26
@@ -17,8 +17,6 @@ · 16 unmodified lines
17#include <fstream> // to load voxels from file17#include <fstream> // to load voxels from file
18#include <pthread.h>18#include <pthread.h>
19 19
20#include <glm/gtc/random.hpp>
21
22#include <OctalCode.h>20#include <OctalCode.h>
23#include <PacketHeaders.h>21#include <PacketHeaders.h>
24#include <PerfStat.h>22#include <PerfStat.h>
@@ -493,7 +491,6 @@ glm::vec3 VoxelSystem::computeVoxelVertex(const glm::vec3& startVertex, float vo · 468 unmodified lines
493}491}
494 492
495ProgramObject* VoxelSystem::_perlinModulateProgram = 0;493ProgramObject* VoxelSystem::_perlinModulateProgram = 0;
496GLuint VoxelSystem::_permutationNormalTextureID = 0;
497 494
498void VoxelSystem::init() {495void VoxelSystem::init() {
499 496
@@ -585,29 +582,9 @@ void VoxelSystem::init() { · 85 unmodified lines
585 _perlinModulateProgram->addShaderFromSourceFile(QGLShader::Fragment, "resources/shaders/perlin_modulate.frag");582 _perlinModulateProgram->addShaderFromSourceFile(QGLShader::Fragment, "resources/shaders/perlin_modulate.frag");
586 _perlinModulateProgram->link();583 _perlinModulateProgram->link();
587 584
585 _perlinModulateProgram->bind();
588 _perlinModulateProgram->setUniformValue("permutationNormalTexture", 0);586 _perlinModulateProgram->setUniformValue("permutationNormalTexture", 0);
589 587 _perlinModulateProgram->release();
590 // create the permutation/normal texture
591 glGenTextures(1, &_permutationNormalTextureID);
592 glBindTexture(GL_TEXTURE_2D, _permutationNormalTextureID);
593
594 // the first line consists of random permutation offsets
595 unsigned char data[256 * 2 * 3];
596 for (int i = 0; i < 256 * 3; i++) {
597 data[i] = rand() % 256;
598 }
599 // the next, random unit normals
600 for (int i = 256 * 3; i < 256 * 3 * 2; i += 3) {
601 glm::vec3 randvec = glm::sphericalRand(1.0f);
602 data[i] = ((randvec.x + 1.0f) / 2.0f) * 255.0f;
603 data[i + 1] = ((randvec.y + 1.0f) / 2.0f) * 255.0f;
604 data[i + 2] = ((randvec.z + 1.0f) / 2.0f) * 255.0f;
605 }
606 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
607 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
608 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
609
610 glBindTexture(GL_TEXTURE_2D, 0);
611}588}
612 589
613void VoxelSystem::updateFullVBOs() {590void VoxelSystem::updateFullVBOs() {
@@ -734,7 +711,7 @@ void VoxelSystem::applyScaleAndBindProgram(bool texture) { · 120 unmodified lines
734 711
735 if (texture) {712 if (texture) {
736 _perlinModulateProgram->bind();713 _perlinModulateProgram->bind();
737 glBindTexture(GL_TEXTURE_2D, _permutationNormalTextureID);714 glBindTexture(GL_TEXTURE_2D, Application::getInstance()->getTextureCache()->getPermutationNormalTextureID());
738 }715 }
739}716}
740 717