Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
bool TextClass::CreateText () { //local float width = 0; Windowsize* wz = Input->GetWindowsize (); for (unsigned int i = 0; i < Text.size(); i++) { char Symbol; TextModel* Model; Symbol = Text[i]; for (unsigned int z = 0; z < TextUVdata.size(); z++) { if (Symbol == TextUVdata[z]->symbol) { Model = new TextModel; Model->Symbol = Symbol; //Triangle 1 Point 1 Model->x[0] = width; Model->y[0] = this->PosY + TextUVdata[z]->h * wz->Pixel_in_float_height; Model->z[0] = this->PosZ; Model->u[0] = TextUVdata[z]->x; Model->v[0] = TextUVdata[z]->y + TextUVdata[z]->h; //Triangle 1 Point 2 Model->x[1] = width; Model->y[1] = this->PosY; Model->z[1] = this->PosZ; Model->u[1] = TextUVdata[z]->x; Model->v[1] = TextUVdata[z]->y; //Triangle 1 Point 3 Model->x[2] = width + TextUVdata[z]->w * wz->Pixel_in_float_width; Model->y[2] = this->PosY; Model->z[2] = this->PosZ; Model->u[2] = TextUVdata[z]->x + TextUVdata[z]->w; Model->v[2] = TextUVdata[z]->y; //Triangle 2 Point 1 Model->x[3] = width + TextUVdata[z]->w * wz->Pixel_in_float_width; Model->y[3] = this->PosY; Model->z[3] = this->PosZ; Model->u[3] = TextUVdata[z]->x + TextUVdata[z]->w; Model->v[3] = TextUVdata[z]->y; //Triangle 2 Point 2 Model->x[4] = width + TextUVdata[z]->w * wz->Pixel_in_float_width; Model->y[4] = this->PosY + TextUVdata[z]->h * wz->Pixel_in_float_height; Model->z[4] = this->PosZ; Model->u[4] = TextUVdata[z]->x + TextUVdata[z]->w; Model->v[4] = TextUVdata[z]->y + TextUVdata[z]->h; //Triangle 2 Point 3 Model->x[5] = width; Model->y[5] = this->PosY + TextUVdata[z]->h * wz->Pixel_in_float_height; Model->z[5] = this->PosZ; Model->u[5] = TextUVdata[z]->x; Model->v[5] = TextUVdata[z]->y + TextUVdata[z]->h; } } Textmodel.push_back(Model); } return true; } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
bool TextClass::CreateBuffer () { VertexType* vertices; unsigned int* indices; int i; int m_vertexCount = this->Textmodel.size () *6; this->m_indexCount = this->Textmodel.size () *6; // Create the vertex array. vertices = new VertexType[m_vertexCount]; if(!vertices) { return false; } // Create the index array. indices = new unsigned int[m_indexCount]; if(!indices) { return false; } // Load the vertex array and index array with data. int c = 0; int t = 0; while (c < this->Textmodel.size ()) { for (int z = 0; z < 6; z++) { vertices[c].x = Textmodel[t]->x[z]; vertices[c].y = Textmodel[t]->y[z]; vertices[c].z = Textmodel[t]->z[z]; vertices[c].tu = Textmodel[t]->u[z]; vertices[c].tv = Textmodel[t]->u[z]; vertices[c].nx = 0; vertices[c].ny = 1; vertices[c].nz = 0; indices[c] = c; } t = t + 1; c = c + 1; } // Allocate an OpenGL vertex array object. OpenGL->glGenVertexArrays(1, &m_vertexArrayId); // Bind the vertex array object to store all the buffers and vertex attributes we create here. OpenGL->glBindVertexArray(m_vertexArrayId); // Generate an ID for the vertex buffer. OpenGL->glGenBuffers(1, &m_vertexBufferId); // Bind the vertex buffer and load the vertex (position, texture, and normal) data into the vertex buffer. OpenGL->glBindBuffer(GL_ARRAY_BUFFER, m_vertexBufferId); OpenGL->glBufferData(GL_ARRAY_BUFFER, m_vertexCount * sizeof(VertexType), vertices, GL_STATIC_DRAW); // Enable the three vertex array attributes. OpenGL->glEnableVertexAttribArray(0); // Vertex position. OpenGL->glEnableVertexAttribArray(1); // Texture coordinates. OpenGL->glEnableVertexAttribArray(2); // Normals. // Specify the location and format of the position portion of the vertex buffer. OpenGL->glBindBuffer(GL_ARRAY_BUFFER, m_vertexBufferId); OpenGL->glVertexAttribPointer(0, 3, GL_FLOAT, false, sizeof(VertexType), 0); // Specify the location and format of the texture coordinate portion of the vertex buffer. OpenGL->glBindBuffer(GL_ARRAY_BUFFER, m_vertexBufferId); OpenGL->glVertexAttribPointer(1, 2, GL_FLOAT, false, sizeof(VertexType), (unsigned char*)NULL + (3 * sizeof(float))); // Specify the location and format of the normal vector portion of the vertex buffer. OpenGL->glBindBuffer(GL_ARRAY_BUFFER, m_vertexBufferId); OpenGL->glVertexAttribPointer(2, 3, GL_FLOAT, false, sizeof(VertexType), (unsigned char*)NULL + (5 * sizeof(float))); // Generate an ID for the index buffer. OpenGL->glGenBuffers(1, &m_indexBufferId); // Bind the index buffer and load the index data into it. OpenGL->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBufferId); OpenGL->glBufferData(GL_ELEMENT_ARRAY_BUFFER, m_indexCount* sizeof(unsigned int), indices, GL_STATIC_DRAW); // Now that the buffers have been loaded we can release the array data. delete [] vertices; vertices = 0; delete [] indices; indices = 0; return true; } |
Community-Fossil
Community-Fossil
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »Volker_Neff« (07.10.2013, 13:53)
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
if (Symbol == TextUVdata[z]->symbol) { Model = new TextModel; Model->Symbol = Symbol; //Point 1 Model->x[0] = width; Model->y[0] = this->PosY; Model->z[0] = this->PosZ + TextUVdata[z]->hight * wz->Pixel_in_float_height; Model->u[0] = TextUVdata[z]->x; Model->v[0] = TextUVdata[z]->y + TextUVdata[z]->h; //Point 2 Model->x[1] = width; Model->y[1] = this->PosY; Model->z[1] = this->PosZ; Model->u[1] = TextUVdata[z]->x; Model->v[1] = TextUVdata[z]->y; //Point 3 Model->x[2] = width + TextUVdata[z]->width * wz->Pixel_in_float_width; Model->y[2] = this->PosY; Model->z[2] = this->PosZ; Model->u[2] = TextUVdata[z]->x + TextUVdata[z]->w; Model->v[2] = TextUVdata[z]->y; //Point 4 Model->x[3] = width + TextUVdata[z]->width * wz->Pixel_in_float_width; Model->y[3] = this->PosY; Model->z[3] = this->PosZ + TextUVdata[z]->hight * wz->Pixel_in_float_height; Model->u[3] = TextUVdata[z]->x + TextUVdata[z]->w; Model->v[3] = TextUVdata[z]->y + TextUVdata[z]->h; //Set new width width = width + TextUVdata[z]->width * wz->Pixel_in_float_height; |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
while (c < this->Textmodel.size ()) { for (int z = 0; z < 4; z++) { vertices[t].x = Textmodel[c]->x[z]; vertices[t].y = Textmodel[c]->y[z]; vertices[t].z = Textmodel[c]->z[z]; vertices[t].tu = Textmodel[c]->u[z]; vertices[t].tv = Textmodel[c]->u[z]; vertices[t].nx = 0; vertices[t].ny = 1; vertices[t].nz = 0; indices[t] = t; t = t + 1; } c = c + 1; } |
Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von »Volker_Neff« (09.10.2013, 23:39)
Community-Fossil
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
void Text::setText(const std::string &text){ Font* font = static_cast<Font*>(getComponent("Font")); Sprite* sprite = static_cast<Sprite*>(getComponent("Sprite")); if(font && sprite){ m_text = text; // generate buffer std::vector<unsigned int> indices; std::vector<vec2> vertices; std::vector<vec2> texCoords; indices.resize(m_text.length()*6); vertices.resize(m_text.length()*4); texCoords.resize(m_text.length()*4); vec2 offset = vec2(); Font::character c; unsigned int index = 0; for(unsigned int i = 0; i < m_text.length()*6; i += 6){ // indices indices[i] = index; indices[i+1] = index+1; indices[i+2] = index+2; indices[i+3] = index; indices[i+4] = index+2; indices[i+5] = index+3; index += 4; } index = 0; for(unsigned int i = 0; i < m_text.length()*4; i += 4){ // special characters if(m_text.at(index) == ' '){ // space offset.x += font->m_spaceBar+font->m_space.x; index++; continue; } else if(m_text.at(index) == '\t'){ // tab offset.x += font->m_tab+font->m_space.x; index++; continue; } else if(m_text.at(index) == '\n'){ // new line offset.y -= 1.0f+font->m_space.y; offset.x = 0.0f; index++; continue; } c = font->getCharacter(m_text.at(index)); // vertices vertices[i] = vec2(offset.x, offset.y); vertices[i+1] = vec2(offset.x+c.size.x, offset.y); vertices[i+2] = vec2(offset.x+c.size.x, offset.y+c.size.y); vertices[i+3] = vec2(offset.x, offset.y+c.size.y); // texture coordinates texCoords[i] = vec2(c.min.x, c.min.y); texCoords[i+1] = vec2(c.max.x, c.min.y); texCoords[i+2] = vec2(c.max.x, c.max.y); texCoords[i+3] = vec2(c.min.x, c.max.y); offset.x += c.size.x+font->m_space.x; index++; } VBO<unsigned int>* indexBuffer = new VBO<unsigned int>("index0", GL_ELEMENT_ARRAY_BUFFER); indexBuffer->fill(indices, indices.size()*sizeof(unsigned int), GL_STATIC_DRAW); VBO<vec2>* vertexBuffer = new VBO<vec2>("vertex0", GL_ARRAY_BUFFER); vertexBuffer->fill(vertices, vertices.size()*sizeof(vec2), GL_STATIC_DRAW); VBO<vec2>* texCoordBuffer = new VBO<vec2>("texCoord0", GL_ARRAY_BUFFER); texCoordBuffer->fill(texCoords, texCoords.size()*sizeof(vec2), GL_STATIC_DRAW); sprite->m_mesh->generateMesh(indexBuffer, vertexBuffer, texCoordBuffer); // drops } } |
Community-Fossil
Werbeanzeige