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
Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von »stef« (07.09.2012, 22:55)
Ja
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »stef« (01.09.2012, 00:16)
Definitiv Ja. Was du falsch machst, kann ich nicht sagen, ohne gesehen zu haben, was du machst...
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 |
void CFigure::CopyBufferData() { // transform data before copy to GPU RAM Transform(); GL::glBindVertexArray(m_unVAO); { // first bind buffer via handle handle GL::glBindBuffer(GL_ARRAY_BUFFER, m_unVBO); // call glBufferData with correct size and NULL-Pointer to allocate memory for the following calls of glBufferSubData GL::glBufferData(GL_ARRAY_BUFFER, sizeof(CVector3)*m_sNumberOfVertices + sizeof(CVector3)*m_sNumberOfVertices + sizeof(CVector2)*m_sNumberOfVertices, NULL, GL_STATIC_DRAW); // call glBufferSubData to actualy fill the buffers GL::glBufferSubData(GL_ARRAY_BUFFER, 0 , sizeof(CVector3)*m_sNumberOfVertices, &m_v3Position[0]); GL::glBufferSubData(GL_ARRAY_BUFFER, sizeof(CVector3)*m_sNumberOfVertices , sizeof(CVector3)*m_sNumberOfVertices, &m_v3Normal[0]); GL::glBufferSubData(GL_ARRAY_BUFFER, sizeof(CVector3)*m_sNumberOfVertices + sizeof(CVector3)*m_sNumberOfVertices, sizeof(CVector2)*m_sNumberOfVertices, &m_v2Texture[0]); // buffer has three sections for position, normals and texture coordinates GL::glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (GLvoid*)0); GL::glEnableVertexAttribArray(0); GL::glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (GLvoid*)(sizeof(CVector3)*m_sNumberOfVertices)); GL::glEnableVertexAttribArray(1); GL::glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, (GLvoid*)(sizeof(CVector3)*m_sNumberOfVertices + sizeof(CVector3)*m_sNumberOfVertices)); GL::glDisableVertexAttribArray(2); // only enabled if texture is set } GL::glBindVertexArray(0); // unbind VAO to avoid unwanted changes } |
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 |
void CFigure_Torus::DrawInstanced(GLsizei primcount, GLuint unVBO, vector& v_m44MVM, vector& v_m33NM) { // draw torus int i; GL::glBindVertexArray(m_unVAO); { GL::glBindBuffer(GL_ARRAY_BUFFER, unVBO); GL::glBufferData (GL_ARRAY_BUFFER, sizeof(CMatrix44) + sizeof(CMatrix33) * primcount, NULL, GL_DYNAMIC_DRAW); GL::glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(CMatrix44) * primcount, &v_m44MVM[0]); GL::glBufferSubData(GL_ARRAY_BUFFER, sizeof(CMatrix44) * primcount, sizeof(CMatrix33) * primcount, &v_m33NM[0]); GL::glVertexAttribPointer(3, 16, GL_FLOAT, GL_FALSE, 0, (GLvoid*)0); GL::glEnableVertexAttribArray(3); GL::glVertexAttribDivisor(3, 1); GL::glVertexAttribPointer(4, 9, GL_FLOAT, GL_FALSE, 0, (GLvoid*)(sizeof(CMatrix44) * primcount)); GL::glEnableVertexAttribArray(4); GL::glVertexAttribDivisor(4, 1); if(m_unTexture2D) glBindTexture(GL_TEXTURE_2D, m_unTexture2D); if(m_unTextureCube) glBindTexture(GL_TEXTURE_CUBE_MAP, m_unTextureCube); //glCullFace(GL_FRONT); //for(i=0; i<m_snumberofsegments; i++)="" // glDrawArrays(GL_TRIANGLE_STRIP, i*(m_sNumberOfSegments*2+2) , m_sNumberOfSegments*2+2); glCullFace(GL_BACK); for(i=0; i<m_snumberofsegments; i++)="" GL::glDrawArraysInstanced(GL_TRIANGLE_STRIP, i*(m_sNumberOfSegments*2+2) , m_sNumberOfSegments*2+2, primcount); if(m_unTexture2D) glBindTexture(GL_TEXTURE_2D, 0); if(m_unTextureCube) glBindTexture(GL_TEXTURE_CUBE_MAP, 0); } GL::glBindVertexArray(0); } |
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 |
#version 330 precision highp float; precision highp int; // already transformed by view matrix !!! uniform vec3 u_v3LightPos; uniform mat4 u_m4PM; layout (location = 0) in vec3 _v3Vertex; layout (location = 1) in vec3 _v3Normal; layout (location = 2) in vec2 _v2Texture; layout (location = 3) in mat4 u_m4MVM; layout (location = 4) in mat3 u_m3NM; out vec3 v3Vertex_; out vec3 v3Normal_; out vec2 v2Texture_; out vec3 v3VertexToLight_; out vec4 v4SecondaryColor_; void main (void) { vec3 v3HalfWay; vec4 v4Temp; float fNdotL; float fNdotH; // position v4Temp.xyz = _v3Vertex; v4Temp.w = 1.0; v4Temp = u_m4MVM * v4Temp; v3Vertex_ = v4Temp.xyz; v4Temp.xyz = v3Vertex_; v4Temp.w = 1.0; gl_Position = u_m4PM * v4Temp; // normals v3Normal_ = normalize(u_m3NM * _v3Normal); // calculate and normalized vertex to light vector v3VertexToLight_ = normalize(u_v3LightPos - v3Vertex_); // calculate normals dot vertex to light vector fNdotL = max(0.0, dot(v3Normal_, v3VertexToLight_)); // calculate half way for specular light v3HalfWay = normalize( normalize(vec3(0.0, 0.0, 0.0) - v3Vertex_) + normalize(u_v3LightPos - v3Vertex_) ); fNdotH = max(0.0, dot(v3Normal_, v3HalfWay)); // specular light v4SecondaryColor_ = (fNdotL > 0.0) ? vec4(pow(fNdotH, 128.0)) : vec4(0.0); // set texture unchanged v2Texture_ = _v2Texture; } |
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »stef« (03.09.2012, 11:05)
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »stef« (03.09.2012, 11:06)
C-/C++-Quelltext |
|
1 |
GL::glBufferData (GL_ARRAY_BUFFER, sizeof(CMatrix44) + sizeof(CMatrix33) * primcount, NULL, GL_DYNAMIC_DRAW); |
Werbeanzeige