Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Fragment::generateFragment(glm::vec3 fPos, glm::vec3 fAng){
- renderAng = fAng;
- renderPos = fPos;
- //create a single fragment
- for(int x = 0; x <FRAGMENTSIZE; x++) {
- for(int y = 0; y <FRAGMENTSIZE; y++){
- for(int z = 0; z<FRAGMENTSIZE; z++){
- fragment[x][y][z] = 1;
- }
- }
- }
- int render = 0;
- // initate vectors to store the information about the visible faces
- std::vector<GLfloat> chunkVertices;
- std::vector<GLfloat> chunkNormals;
- std::vector<GLfloat> chunkTextures;
- //analyze each face to see if its visible
- for(int x = 0; x <FRAGMENTSIZE; x++) {
- for(int y = 0; y<FRAGMENTSIZE; y++){
- for(int z = 0; z<FRAGMENTSIZE; z++){
- if(fragment[x][y][z] != 0) {
- render = 0;
- if(fragment[x+1][y][z]==0 || x == FRAGMENTSIZE-1) {
- renderVisible[renderIndex][0]=1;
- render=1;
- }
- if(fragment[x-1][y][z]==0 || x == 0) {
- renderVisible[renderIndex][1]=1;
- render=1;
- }
- if(fragment[x][y+1][z]==0 || y == FRAGMENTSIZE-1) {
- renderVisible[renderIndex][5]=1;
- render=1;
- }
- if(fragment[x][y-1][z]==0 || y == 0) {
- renderVisible[renderIndex][4]=1;
- render=1;
- }
- if(fragment[x][y][z+1]==0 || z == FRAGMENTSIZE-1) {
- renderVisible[renderIndex][3]=1;
- render=1;
- }
- if(fragment[x][y][z-1]==0 || z == 0) {
- renderVisible[renderIndex][2]=1;
- render=1;
- }
- int side = 0;
- int draw = 0;
- int sideadd = 0;
- // if one or more faces are visible
- if(render) {
- for(int idx = 0; idx < 6; idx++) {
- draw = renderVisible[renderIndex][idx];
- if(draw) {
- // adding texture points
- for(int i = idx*6; i < idx*6+6; i++) {
- chunkTextures.push_back(texture_data[i]);
- }
- // adding surface normals and vertexes
- // sideadd variable is used to insert the proper coordinates into each face
- for(int i = idx*12; i < idx*12+12; i++) {
- switch(side) {
- case 0:
- sideadd = x;
- break;
- case 1:
- sideadd = y;
- break;
- case 2:
- sideadd = z;
- break;
- }
- chunkVertices.push_back(vertice_data[i]+sideadd);
- chunkNormals.push_back(normals[i]);
- side++; if(side>2) {side=0;}
- }
- }
- }
- }
- }
- } // z
- } // y
- } // x
- // converting the vectors to buffers that can be drawn in the main rendering loop
- glGenBuffers(1, &normalbuf);
- glBindBuffer(GL_ARRAY_BUFFER, normalbuf);
- glBufferData(GL_ARRAY_BUFFER, chunkNormals.size()*sizeof(chunkNormals[0]), &chunkNormals, GL_STATIC_DRAW);
- glGenBuffers(1, &vertexbuf);
- glBindBuffer(GL_ARRAY_BUFFER, vertexbuf);
- glBufferData(GL_ARRAY_BUFFER, chunkVertices.size()*sizeof(chunkVertices[0]), &chunkVertices, GL_STATIC_DRAW);
- glGenBuffers(1, &uvbuf);
- glBindBuffer(GL_ARRAY_BUFFER, uvbuf);
- glBufferData(GL_ARRAY_BUFFER, chunkTextures.size()*sizeof(chunkTextures[0]), &chunkTextures, GL_STATIC_DRAW);
- }
- First-chance exception at 0x69977420 in minecraft.exe: 0xC0000005: Access violation reading location 0x00300000.
- Unhandled exception at 0x77a415de (ntdll.dll) in minecraft.exe: 0xC0000005: Access violation reading location 0x00300000.
- static const GLfloat texture_data[] = {
- //right
- 0.66f, 1.0f,
- 0.33f, 0.5f,
- 0.33f, 1.0f,
- //right
- 0.33f, 0.5f,
- 0.66f, 1.0f,
- 0.66f, 0.5f,
- //left
- 0.0f, 0.0f,
- 0.33f, 0.0f,
- 0.33f, 0.5f,
- //left
- 0.0f, 0.0f,
- 0.33f, 0.5f,
- 0.0f, 0.5f,
- // rear
- 0.33f, 0.5f,
- 0.66f, 0.0f,
- 0.66f, 0.5f,
- //rear
- 0.33f, 0.5f,
- 0.33f, 0.0f,
- 0.66f, 0.0f,
- //front
- 0.33f, 1.0f,
- 0.33f, 0.5f,
- 0.0f, 0.5f,
- //front
- 0.0f, 1.0f,
- 0.33f, 1.0f,
- 0.0f, 0.5f,
- //bottom
- 1.0f, 0.5f,
- 0.666f, 0.0f,
- 1.0f, 0.0f,
- //bottom
- 1.0f, 0.5f,
- 0.666f, 0.5f,
- 0.666f, 0.0f,
- // top
- 0.6666f, 0.5f,
- 0.666f, 1.0f,
- 1.0f, 1.0f,
- // top
- 0.6666f, 0.5f,
- 1.00f, 1.0f,
- 1.00f, 0.5f
- };
- static const GLfloat vertice_data[] = {
- //right
- 1.0f, 1.0f, 1.0f,
- 1.0f,-1.0f,-1.0f,
- 1.0f, 1.0f,-1.0f,
- //right
- 1.0f,-1.0f,-1.0f,
- 1.0f, 1.0f, 1.0f,
- 1.0f,-1.0f, 1.0f,
- //left
- -1.0f,-1.0f,-1.0f,
- -1.0f,-1.0f, 1.0f,
- -1.0f, 1.0f, 1.0f,
- //left
- -1.0f,-1.0f,-1.0f,
- -1.0f, 1.0f, 1.0f,
- -1.0f, 1.0f,-1.0f,
- //rear
- 1.0f, 1.0f,-1.0f,
- -1.0f,-1.0f,-1.0f,
- -1.0f, 1.0f,-1.0f,
- //rear
- 1.0f, 1.0f,-1.0f,
- 1.0f,-1.0f,-1.0f,
- -1.0f,-1.0f,-1.0f,
- //front
- -1.0f, 1.0f, 1.0f,
- -1.0f,-1.0f, 1.0f,
- 1.0f,-1.0f, 1.0f,
- //front
- 1.0f, 1.0f, 1.0f,
- -1.0f, 1.0f, 1.0f,
- 1.0f,-1.0f, 1.0f,
- //bottom
- 1.0f,-1.0f, 1.0f,
- -1.0f,-1.0f,-1.0f,
- 1.0f,-1.0f,-1.0f,
- //bottom
- 1.0f,-1.0f, 1.0f,
- -1.0f,-1.0f, 1.0f,
- -1.0f,-1.0f,-1.0f,
- //top
- 1.0f, 1.0f, 1.0f,
- 1.0f, 1.0f,-1.0f,
- -1.0f, 1.0f,-1.0f,
- //top
- 1.0f, 1.0f, 1.0f,
- -1.0f, 1.0f,-1.0f,
- -1.0f, 1.0f, 1.0f
- };
- static const GLfloat normals[] = {
- //right
- 1.0f, 0.0f, 0.0f,
- 1.0f, 0.0f, 0.0f,
- 1.0f, 0.0f, 0.0f,
- //right
- 1.0f, 0.0f, 0.0f,
- 1.0f, 0.0f, 0.0f,
- 1.0f, 0.0f, 0.0f,
- //left
- -1.0f, 0.0f, 0.0f,
- -1.0f, 0.0f, 0.0f,
- -1.0f, 0.0f, 0.0f,
- //left
- -1.0f, 0.0f, 0.0f,
- -1.0f, 0.0f, 0.0f,
- -1.0f, 0.0f, 0.0f,
- //rear
- 0.0f, 0.0f, -1.0f,
- 0.0f, 0.0f, -1.0f,
- 0.0f, 0.0f, -1.0f,
- //rear
- 0.0f, 0.0f, -1.0f,
- 0.0f, 0.0f, -1.0f,
- 0.0f, 0.0f, -1.0f,
- //front
- 0.0f, 0.0f, 1.0f,
- 0.0f, 0.0f, 1.0f,
- 0.0f, 0.0f, 1.0f,
- //front
- 0.0f, 0.0f, 1.0f,
- 0.0f, 0.0f, 1.0f,
- 0.0f, 0.0f, 1.0f,
- //bottom
- 0.0f, -1.0f, 0.0f,
- 0.0f, -1.0f, 0.0f,
- 0.0f, -1.0f, 0.0f,
- //bottom
- 0.0f, -1.0f, 0.0f,
- 0.0f, -1.0f, 0.0f,
- 0.0f, -1.0f, 0.0f,
- //top
- 0.0f, 1.0f, 0.0f,
- 0.0f, 1.0f, 0.0f,
- 0.0f, 1.0f, 0.0f,
- //top
- 0.0f, 1.0f, 0.0f,
- 0.0f, 1.0f, 0.0f,
- 0.0f, 1.0f, 0.0f
- };
Add Comment
Please, Sign In to add comment