Solo usuarios registrados pueden comentar y agradecer, Logueate o Registrate

Autor Topic: takumi12 - VAO (Vertex Array Object) SHADER MAIN 5.2  (Visto 11363 veces)

0 Miembros and 1 Guest are viewing this topic.

Offline mavine #30 Posteado: March 28, 2025, 11:25:21 PM

  • 0 puntos por ventas
  • *
  • Rank: Principiante
  • Posts: 11
  • Gracias recibida: 2
  • br
You're missing the important part that was already mentioned earlier:

"The problem remains how to load the shader and correctly position the transformation values ​​for the camera, view, and model." – takumi12 angryy2

If your model doesn’t appear, it's not the shader itself — it's likely that your camera/view/projection setup is wrong, and the object is rendered outside the visible space.

Code: [Select]
void BMD::RenderVertexBuffer(int textureIndex, Mesh_t* m, int vertex_index, vec3_t* vertices, vec2_t* textCoords)
{
const auto texture = Bitmaps.GetTexture(textureIndex);
if (!texture) return;

GLuint textureID = texture->TextureNumber;
if (!glIsTexture(textureID)) return;

glm::mat4 model = glm::mat4(1.0f);

float distanceBehind = -1.0f;
float heightAbove = 0.9f;
float yaw = -0.8;// glm::radians(CameraAngle[0])* glm::radians(CameraFOV);

glm::vec3 characterPosition = glm::vec3(CameraPosition[0], CameraPosition[1], CameraPosition[2]);

glm::vec3 behindOffset = glm::vec3(
cosf(yaw) * -distanceBehind,
sinf(yaw) * -distanceBehind,
0.0f
);

glm::vec3 cameraPosition = characterPosition + behindOffset;
cameraPosition.z += heightAbove;

glm::mat4 view = glm::lookAt(
cameraPosition,
characterPosition,
glm::vec3(0.0f, 0.0f, 1.0f)
);

glm::mat4 projection = glm::perspective(glm::radians(CameraFOV),
(float)WindowWidth / (float)WindowHeight, CameraViewNear, CameraViewFar * 1.4f);

GLuint shader_id = gShaderGL->GetShaderId();
glUseProgram(shader_id);

// Matrici al vertex shader
glUniformMatrix4fv(glGetUniformLocation(shader_id, "model"), 1, GL_FALSE, glm::value_ptr(model));
glUniformMatrix4fv(glGetUniformLocation(shader_id, "view"), 1, GL_FALSE, glm::value_ptr(view));
glUniformMatrix4fv(glGetUniformLocation(shader_id, "projection"), 1, GL_FALSE, glm::value_ptr(projection));

// Texture
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textureID);
glUniform1i(glGetUniformLocation(shader_id, "texture1"), 0);

glBindVertexArray(m->VAO);

// Vertex
glBindBuffer(GL_ARRAY_BUFFER, m->VBO_Vertices);
glBufferSubData(GL_ARRAY_BUFFER, 0, vertex_index * sizeof(vec3_t), vertices);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
glEnableVertexAttribArray(0);

// Texture Coord
glBindBuffer(GL_ARRAY_BUFFER, m->VBO_TexCoords);
glBufferSubData(GL_ARRAY_BUFFER, 0, vertex_index * sizeof(vec2_t), textCoords);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, (void*)0);
glEnableVertexAttribArray(1);

// Draw call
glDrawElements(GL_TRIANGLES, vertex_index, GL_UNSIGNED_SHORT, 0);

glBindVertexArray(0);
glUseProgram(0);
}

Use this hardcoded snippet to test and adjust until your object becomes visible.



exactly like that , the transfom from camera pos is taken from the character's position and it is always returned to BodyOrigin

Samuel 
Where do I call this function?   void BMD::RenderVertexBuffer(int textureIndex, Mesh_t* m, int vertex_index, vec3_t* vertices, vec2_t* textCoords)


Offline z0lik #31 Posteado: March 29, 2025, 02:56:08 AM

  • 0 puntos por ventas
  • *
  • Rank: Principiante
  • Posts: 7
  • Gracias recibida: 3
  • it
You're missing the important part that was already mentioned earlier:

"The problem remains how to load the shader and correctly position the transformation values ​​for the camera, view, and model." – takumi12 angryy2

If your model doesn’t appear, it's not the shader itself — it's likely that your camera/view/projection setup is wrong, and the object is rendered outside the visible space.

Code: [Select]
void BMD::RenderVertexBuffer(int textureIndex, Mesh_t* m, int vertex_index, vec3_t* vertices, vec2_t* textCoords)
{
const auto texture = Bitmaps.GetTexture(textureIndex);
if (!texture) return;

GLuint textureID = texture->TextureNumber;
if (!glIsTexture(textureID)) return;

glm::mat4 model = glm::mat4(1.0f);

float distanceBehind = -1.0f;
float heightAbove = 0.9f;
float yaw = -0.8;// glm::radians(CameraAngle[0])* glm::radians(CameraFOV);

glm::vec3 characterPosition = glm::vec3(CameraPosition[0], CameraPosition[1], CameraPosition[2]);

glm::vec3 behindOffset = glm::vec3(
cosf(yaw) * -distanceBehind,
sinf(yaw) * -distanceBehind,
0.0f
);

glm::vec3 cameraPosition = characterPosition + behindOffset;
cameraPosition.z += heightAbove;

glm::mat4 view = glm::lookAt(
cameraPosition,
characterPosition,
glm::vec3(0.0f, 0.0f, 1.0f)
);

glm::mat4 projection = glm::perspective(glm::radians(CameraFOV),
(float)WindowWidth / (float)WindowHeight, CameraViewNear, CameraViewFar * 1.4f);

GLuint shader_id = gShaderGL->GetShaderId();
glUseProgram(shader_id);

// Matrici al vertex shader
glUniformMatrix4fv(glGetUniformLocation(shader_id, "model"), 1, GL_FALSE, glm::value_ptr(model));
glUniformMatrix4fv(glGetUniformLocation(shader_id, "view"), 1, GL_FALSE, glm::value_ptr(view));
glUniformMatrix4fv(glGetUniformLocation(shader_id, "projection"), 1, GL_FALSE, glm::value_ptr(projection));

// Texture
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textureID);
glUniform1i(glGetUniformLocation(shader_id, "texture1"), 0);

glBindVertexArray(m->VAO);

// Vertex
glBindBuffer(GL_ARRAY_BUFFER, m->VBO_Vertices);
glBufferSubData(GL_ARRAY_BUFFER, 0, vertex_index * sizeof(vec3_t), vertices);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
glEnableVertexAttribArray(0);

// Texture Coord
glBindBuffer(GL_ARRAY_BUFFER, m->VBO_TexCoords);
glBufferSubData(GL_ARRAY_BUFFER, 0, vertex_index * sizeof(vec2_t), textCoords);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, (void*)0);
glEnableVertexAttribArray(1);

// Draw call
glDrawElements(GL_TRIANGLES, vertex_index, GL_UNSIGNED_SHORT, 0);

glBindVertexArray(0);
glUseProgram(0);
}

Use this hardcoded snippet to test and adjust until your object becomes visible.



exactly like that , the transfom from camera pos is taken from the character's position and it is always returned to BodyOrigin

Samuel 
Where do I call this function?   void BMD::RenderVertexBuffer(int textureIndex, Mesh_t* m, int vertex_index, vec3_t* vertices, vec2_t* textCoords)

zzzBMD.cpp
Code: [Select]
void BMD::RenderMesh(int meshIndex, int renderFlags, float alpha, int blendMeshIndex, float blendMeshAlpha, float blendMeshTextureCoordU, float blendMeshTextureCoordV, int explicitTextureIndex)

sven-n/MuMain part of code
Code: [Select]
void BMD::RenderMesh(int meshIndex, int renderFlags, float alpha, int blendMeshIndex, float blendMeshAlpha, float blendMeshTextureCoordU, float blendMeshTextureCoordV, int explicitTextureIndex)
{
    if (meshIndex >= NumMeshs || meshIndex < 0) return;

    Mesh_t* m = &Meshs[meshIndex];
    if (m->NumTriangles == 0) return;

    float wave = static_cast<long>(WorldTime) % 10000 * 0.0001f;

    int textureIndex = IndexTexture[m->Texture];
    if (textureIndex == BITMAP_HIDE)
    {
        return;
    }

    if (textureIndex == BITMAP_WATER)
    {
        textureIndex = BITMAP_WATER + WaterTextureNumber;
    }

    if (explicitTextureIndex != -1)
    {
        textureIndex = explicitTextureIndex;
    }

    const auto texture = Bitmaps.GetTexture(textureIndex);
    if (texture->IsSkin && HideSkin)
    {
        return;
    }

    if (texture->IsHair && HideSkin)
    {
        return;
    }

    bool EnableWave = false;
    int streamMesh = static_cast<u_char>(this->StreamMesh);
    if (m->m_csTScript != nullptr)
    {
        if (m->m_csTScript->getStreamMesh())
        {
            streamMesh = meshIndex;
        }
    }

    if ((meshIndex == blendMeshIndex || meshIndex == streamMesh)
        && (blendMeshTextureCoordU != 0.f || blendMeshTextureCoordV != 0.f))
    {
        EnableWave = true;
    }

    bool enableLight = LightEnable;
    if (meshIndex == StreamMesh)
    {
        glColor3fv(BodyLight);
        enableLight = false;
    }
    else if (enableLight)
    {
        for (int j = 0; j < m->NumNormals; j++)
        {
            VectorScale(BodyLight, IntensityTransform[meshIndex][j], LightTransform[meshIndex][j]);
        }
    }

    int finalRenderFlags = renderFlags;
    if ((renderFlags & RENDER_COLOR) == RENDER_COLOR)
    {
        finalRenderFlags = RENDER_COLOR;
        if ((renderFlags & RENDER_BRIGHT) == RENDER_BRIGHT)
        {
            EnableAlphaBlend();
        }
        else if ((renderFlags & RENDER_DARK) == RENDER_DARK)
        {
            EnableAlphaBlendMinus();
        }
        else
        {
            DisableAlphaBlend();
        }

        if ((renderFlags & RENDER_NODEPTH) == RENDER_NODEPTH)
        {
            DisableDepthTest();
        }

        DisableTexture();
        if (alpha >= 0.99f)
        {
            glColor3fv(BodyLight);
        }
        else
        {
            EnableAlphaTest();
            glColor4f(BodyLight[0], BodyLight[1], BodyLight[2], alpha);
        }
    }
    else if ((renderFlags & RENDER_CHROME) == RENDER_CHROME ||
        (renderFlags & RENDER_CHROME2) == RENDER_CHROME2 ||
        (renderFlags & RENDER_CHROME3) == RENDER_CHROME3 ||
        (renderFlags & RENDER_CHROME4) == RENDER_CHROME4 ||
        (renderFlags & RENDER_CHROME5) == RENDER_CHROME5 ||
        (renderFlags & RENDER_CHROME6) == RENDER_CHROME6 ||
        (renderFlags & RENDER_CHROME7) == RENDER_CHROME7 ||
        (renderFlags & RENDER_METAL) == RENDER_METAL ||
        (renderFlags & RENDER_OIL) == RENDER_OIL
        )
    {
        if (m->m_csTScript != nullptr)
        {
            if (m->m_csTScript->getNoneBlendMesh()) return;
        }

        if (m->NoneBlendMesh)
            return;

        finalRenderFlags = RENDER_CHROME;
        if ((renderFlags & RENDER_CHROME4) == RENDER_CHROME4)
        {
            finalRenderFlags = RENDER_CHROME4;
        }
        if ((renderFlags & RENDER_OIL) == RENDER_OIL)
        {
            finalRenderFlags = RENDER_OIL;
        }

        float Wave2 = (int)WorldTime % 5000 * 0.00024f - 0.4f;

        vec3_t L = { (float)(cos(WorldTime * 0.001f)), (float)(sin(WorldTime * 0.002f)), 1.f };
        for (int j = 0; j < m->NumNormals; j++)
        {
            if (j > MAX_VERTICES) break;
            const auto normal = NormalTransform[meshIndex][j];

            if ((renderFlags & RENDER_CHROME2) == RENDER_CHROME2)
            {
                g_chrome[j][0] = (normal[2] + normal[0]) * 0.8f + Wave2 * 2.f;
                g_chrome[j][1] = (normal[1] + normal[0]) * 1.0f + Wave2 * 3.f;
            }
            else if ((renderFlags & RENDER_CHROME3) == RENDER_CHROME3)
            {
                g_chrome[j][0] = DotProduct(normal, LightVector);
                g_chrome[j][1] = 1.f - DotProduct(normal, LightVector);
            }
            else if ((renderFlags & RENDER_CHROME4) == RENDER_CHROME4)
            {
                g_chrome[j][0] = DotProduct(normal, L);
                g_chrome[j][1] = 1.f - DotProduct(normal, L);
                g_chrome[j][1] -= normal[2] * 0.5f + wave * 3.f;
                g_chrome[j][0] += normal[1] * 0.5f + L[1] * 3.f;
            }
            else if ((renderFlags & RENDER_CHROME5) == RENDER_CHROME5)
            {
                g_chrome[j][0] = DotProduct(normal, L);
                g_chrome[j][1] = 1.f - DotProduct(normal, L);
                g_chrome[j][1] -= normal[2] * 2.5f + wave * 1.f;
                g_chrome[j][0] += normal[1] * 3.f + L[1] * 5.f;
            }
            else if ((renderFlags & RENDER_CHROME6) == RENDER_CHROME6)
            {
                g_chrome[j][0] = (normal[2] + normal[0]) * 0.8f + Wave2 * 2.f;
                g_chrome[j][1] = (normal[2] + normal[0]) * 0.8f + Wave2 * 2.f;
            }
            else if ((renderFlags & RENDER_CHROME7) == RENDER_CHROME7)
            {
                g_chrome[j][0] = (normal[2] + normal[0]) * 0.8f + static_cast<float>(WorldTime) * 0.00006f;
                g_chrome[j][1] = (normal[2] + normal[0]) * 0.8f + static_cast<float>(WorldTime) * 0.00006f;
            }
            else if ((renderFlags & RENDER_OIL) == RENDER_OIL)
            {
                g_chrome[j][0] = normal[0];
                g_chrome[j][1] = normal[1];
            }
            else if ((renderFlags & RENDER_CHROME) == RENDER_CHROME)
            {
                g_chrome[j][0] = normal[2] * 0.5f + wave;
                g_chrome[j][1] = normal[1] * 0.5f + wave * 2.f;
            }
            else
            {
                g_chrome[j][0] = normal[2] * 0.5f + 0.2f;
                g_chrome[j][1] = normal[1] * 0.5f + 0.5f;
            }
        }

        if ((renderFlags & RENDER_CHROME3) == RENDER_CHROME3
            || (renderFlags & RENDER_CHROME4) == RENDER_CHROME4
            || (renderFlags & RENDER_CHROME5) == RENDER_CHROME5
            || (renderFlags & RENDER_CHROME7) == RENDER_CHROME7
            || (renderFlags & RENDER_BRIGHT) == RENDER_BRIGHT
            )
        {
            if (alpha < 0.99f)
            {
                BodyLight[0] *= alpha;
                BodyLight[1] *= alpha;
                BodyLight[2] *= alpha;
            }

            EnableAlphaBlend();
        }
        else if ((renderFlags & RENDER_DARK) == RENDER_DARK)
            EnableAlphaBlendMinus();
        else if ((renderFlags & RENDER_LIGHTMAP) == RENDER_LIGHTMAP)
            EnableLightMap();
        else if (alpha >= 0.99f)
        {
            DisableAlphaBlend();
        }
        else
        {
            EnableAlphaTest();
        }

        if ((renderFlags & RENDER_NODEPTH) == RENDER_NODEPTH)
        {
            DisableDepthTest();
        }

        if (explicitTextureIndex == -1)
        {
            if ((renderFlags & RENDER_CHROME2) == RENDER_CHROME2)
            {
                BindTexture(BITMAP_CHROME2);
            }
            else if ((renderFlags & RENDER_CHROME3) == RENDER_CHROME3)
            {
                BindTexture(BITMAP_CHROME2);
            }
            else if ((renderFlags & RENDER_CHROME4) == RENDER_CHROME4)
            {
                BindTexture(BITMAP_CHROME2);
            }
            else if ((renderFlags & RENDER_CHROME6) == RENDER_CHROME6)
            {
                BindTexture(BITMAP_CHROME6);
            }
            else if ((renderFlags & RENDER_CHROME) == RENDER_CHROME)
            {
                BindTexture(BITMAP_CHROME);
            }
            else if ((renderFlags & RENDER_METAL) == RENDER_METAL)
            {
                BindTexture(BITMAP_SHINY);
            }
        }
        else
        {
            BindTexture(textureIndex);
        }
    }
    else if (blendMeshIndex <= -2 || m->Texture == blendMeshIndex)
    {
        finalRenderFlags = RENDER_TEXTURE;
        BindTexture(textureIndex);
        if ((renderFlags & RENDER_DARK) == RENDER_DARK)
            EnableAlphaBlendMinus();
        else
            EnableAlphaBlend();

        if ((renderFlags & RENDER_NODEPTH) == RENDER_NODEPTH)
        {
            DisableDepthTest();
        }

        glColor3f(BodyLight[0] * blendMeshAlpha,
            BodyLight[1] * blendMeshAlpha,
            BodyLight[2] * blendMeshAlpha);
        //glColor3f(BlendMeshLight,BlendMeshLight,BlendMeshLight);
        enableLight = false;
    }
    else if ((renderFlags & RENDER_TEXTURE) == RENDER_TEXTURE)
    {
        finalRenderFlags = RENDER_TEXTURE;
        BindTexture(textureIndex);
        if ((renderFlags & RENDER_BRIGHT) == RENDER_BRIGHT)
        {
            EnableAlphaBlend();
        }
        else if ((renderFlags & RENDER_DARK) == RENDER_DARK)
        {
            EnableAlphaBlendMinus();
        }
        else if (alpha < 0.99f || texture->Components == 4)
        {
            EnableAlphaTest();
        }
        else
        {
            DisableAlphaBlend();
        }

        if ((renderFlags & RENDER_NODEPTH) == RENDER_NODEPTH)
        {
            DisableDepthTest();
        }
    }
    else if ((renderFlags & RENDER_BRIGHT) == RENDER_BRIGHT)
    {
        if (texture->Components == 4 || m->Texture == blendMeshIndex)
        {
            return;
        }

        finalRenderFlags = RENDER_BRIGHT;
        EnableAlphaBlend();
        DisableTexture();
        DisableDepthMask();

        if ((renderFlags & RENDER_NODEPTH) == RENDER_NODEPTH)
        {
            DisableDepthTest();
        }
    }
    else
    {
        finalRenderFlags = RENDER_TEXTURE;
    }
    if (renderFlags & RENDER_DOPPELGANGER)
    {
        if (texture->Components != 4)
        {
            EnableCullFace();
            EnableDepthMask();
        }
    }

    bool enableColor = (enableLight && finalRenderFlags == RENDER_TEXTURE)
        || finalRenderFlags == RENDER_CHROME
        || finalRenderFlags == RENDER_CHROME4
        || finalRenderFlags == RENDER_OIL;

    glEnableClientState(GL_VERTEX_ARRAY);
    if (enableColor) glEnableClientState(GL_COLOR_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);

    auto vertices = RenderArrayVertices;
    auto colors = RenderArrayColors;
    auto texCoords = RenderArrayTexCoords;

    int target_vertex_index = -1;
    for (int j = 0; j < m->NumTriangles; j++)
    {
        const auto triangle = &m->Triangles[j];
        for (int k = 0; k < triangle->Polygon; k++)
        {
            const int source_vertex_index = triangle->VertexIndex[k];
            target_vertex_index++;

            VectorCopy(VertexTransform[meshIndex][source_vertex_index], vertices[target_vertex_index]);

            Vector4(BodyLight[0], BodyLight[1], BodyLight[2], alpha, colors[target_vertex_index]);

            auto texco = m->TexCoords[triangle->TexCoordIndex[k]];
            texCoords[target_vertex_index][0] = texco.TexCoordU;
            texCoords[target_vertex_index][1] = texco.TexCoordV;

            int normalIndex = triangle->NormalIndex[k];
            switch (finalRenderFlags)
            {
                case RENDER_TEXTURE:
                {
                    if (EnableWave)
                    {
                        texCoords[target_vertex_index][0] += blendMeshTextureCoordU;
                        texCoords[target_vertex_index][1] += blendMeshTextureCoordV;
                    }

                    if (enableLight)
                    {
                        auto light = LightTransform[meshIndex][normalIndex];
                        Vector4(light[0], light[1], light[2], alpha, colors[target_vertex_index]);
                    }

                    break;
                }
                case RENDER_CHROME:
                {
                    texCoords[target_vertex_index][0] = g_chrome[normalIndex][0];
                    texCoords[target_vertex_index][1] = g_chrome[normalIndex][1];
                    break;
                }
                case RENDER_CHROME4:
                {
                    texCoords[target_vertex_index][0] = g_chrome[normalIndex][0] + blendMeshTextureCoordU;
                    texCoords[target_vertex_index][1] = g_chrome[normalIndex][1] + blendMeshTextureCoordV;
                    break;
                }
                case RENDER_OIL:
                {
                    texCoords[target_vertex_index][0] = g_chrome[normalIndex][0] * texCoords[target_vertex_index][0] + blendMeshTextureCoordU;
                    texCoords[target_vertex_index][1] = g_chrome[normalIndex][1] * texCoords[target_vertex_index][1] + blendMeshTextureCoordV;
                    break;
                }
            }

            if ((renderFlags & RENDER_SHADOWMAP) == RENDER_SHADOWMAP)
            {
                vec3_t pos;
                VectorSubtract(vertices[target_vertex_index], BodyOrigin, pos);

                pos[0] += pos[2] * (pos[0] + 2000.f) / (pos[2] - 4000.f);
                pos[2] = 5.f;

                VectorAdd(pos, BodyOrigin, pos);
            }
            else if ((renderFlags & RENDER_WAVE) == RENDER_WAVE)
            {
                float time_sin = sinf((float)((int)WorldTime + source_vertex_index * 931) * 0.007f) * 28.0f;
                float* normal = NormalTransform[meshIndex][normalIndex];
                for (int iCoord = 0; iCoord < 3; ++iCoord)
                {
                    vertices[target_vertex_index][iCoord] += normal[iCoord] * time_sin;
                }
            }
        }
    }

    glVertexPointer(3, GL_FLOAT, 0, vertices);
    if (enableColor) glColorPointer(4, GL_FLOAT, 0, colors);
    glTexCoordPointer(2, GL_FLOAT, 0, texCoords);

    glDrawArrays(GL_TRIANGLES, 0, m->NumTriangles * 3);

    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    if (enableColor) glDisableClientState(GL_COLOR_ARRAY);
    glDisableClientState(GL_VERTEX_ARRAY);
}
Code: [Select]
    glVertexPointer(3, GL_FLOAT, 0, vertices);
    if (enableColor) glColorPointer(4, GL_FLOAT, 0, colors);
    glTexCoordPointer(2, GL_FLOAT, 0, texCoords);

    glDrawArrays(GL_TRIANGLES, 0, m->NumTriangles * 3);

    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    if (enableColor) glDisableClientState(GL_COLOR_ARRAY);
    glDisableClientState(GL_VERTEX_ARRAY);

delete or replace this part with

Code: [Select]
BMD::RenderVertexBuffer(textureIndex, m, target_vertex_index, vertices, texCoords);

Discord: z0lik

Offline hoanmaster #32 Posteado: July 21, 2025, 03:07:15 AM | Modificado: July 21, 2025, 03:19:39 AM by hoanmaster

  • 0 puntos por ventas
  • *
  • Rank: Dedicado
  • Posts: 31
  • Gracias recibida: 29
  • vn
void BMD::RenderVertexBuffer(int i, Mesh_t* m, int vertex_index, vec3_t* vertices, vec2_t* textCoords)
{
   GLuint shader_id = gShaderGL->GetShaderId();
   glUseProgram(shader_id);
    glm::mat4 model;
    for (int j = 0; j < m->NumVertices; j++)
   {
        Vertex_t* v = &m->Vertices[j];

        float* vp = VertexTransform[j];
        VectorTransform(v->Position, BoneMatrix[v->Node], vp);
       VectorRotate(v->Position, BoneMatrix[v->Node], vp);
      vp[0] = vp[0] * BoneScale + BoneMatrix[v->Node][0][3];
      vp[1] = vp[1] * BoneScale + BoneMatrix[v->Node][1][3];
      vp[2] = vp[2] * BoneScale + BoneMatrix[v->Node][2][3];
        model = glm::translate(glm::mat4(1.0f), vp);
               
    }

   glm::mat4 view = glm::lookAt(glm::vec3(-CameraPosition[0], -CameraPosition[1], -CameraPosition[2]), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
   glm::mat4 projection = glm::perspective(glm::radians(CameraFOV), (float)WindowWidth / (float)WindowHeight, CameraViewNear, CameraViewFar * 1.4f);

   glUniformMatrix4fv(glGetUniformLocation(shader_id, "projection"), 1, GL_FALSE, glm::value_ptr(projection));

   // Enviar la matriz de vista
   glUniformMatrix4fv(glGetUniformLocation(shader_id, "view"), 1, GL_FALSE, glm::value_ptr(view));

   // Enviar la matriz de modelo
   glUniformMatrix4fv(glGetUniformLocation(shader_id, "model"), 1, GL_FALSE, glm::value_ptr(model));


   glBindVertexArray(m->VAO);
   glDrawElements(GL_TRIANGLES, vertex_index, GL_UNSIGNED_SHORT, 0);
   glBindVertexArray(0);
   glUseProgram(0);
}

it will look like this


So good


Offline z0lik #33 Posteado: July 22, 2025, 03:17:26 AM

  • 0 puntos por ventas
  • *
  • Rank: Principiante
  • Posts: 7
  • Gracias recibida: 3
  • it
void BMD::RenderVertexBuffer(int i, Mesh_t* m, int vertex_index, vec3_t* vertices, vec2_t* textCoords)
{
   GLuint shader_id = gShaderGL->GetShaderId();
   glUseProgram(shader_id);
    glm::mat4 model;
    for (int j = 0; j < m->NumVertices; j++)
   {
        Vertex_t* v = &m->Vertices[j];

        float* vp = VertexTransform[j];
        VectorTransform(v->Position, BoneMatrix[v->Node], vp);
       VectorRotate(v->Position, BoneMatrix[v->Node], vp);
      vp[0] = vp[0] * BoneScale + BoneMatrix[v->Node][0][3];
      vp[1] = vp[1] * BoneScale + BoneMatrix[v->Node][1][3];
      vp[2] = vp[2] * BoneScale + BoneMatrix[v->Node][2][3];
        model = glm::translate(glm::mat4(1.0f), vp);
               
    }

   glm::mat4 view = glm::lookAt(glm::vec3(-CameraPosition[0], -CameraPosition[1], -CameraPosition[2]), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
   glm::mat4 projection = glm::perspective(glm::radians(CameraFOV), (float)WindowWidth / (float)WindowHeight, CameraViewNear, CameraViewFar * 1.4f);

   glUniformMatrix4fv(glGetUniformLocation(shader_id, "projection"), 1, GL_FALSE, glm::value_ptr(projection));

   // Enviar la matriz de vista
   glUniformMatrix4fv(glGetUniformLocation(shader_id, "view"), 1, GL_FALSE, glm::value_ptr(view));

   // Enviar la matriz de modelo
   glUniformMatrix4fv(glGetUniformLocation(shader_id, "model"), 1, GL_FALSE, glm::value_ptr(model));


   glBindVertexArray(m->VAO);
   glDrawElements(GL_TRIANGLES, vertex_index, GL_UNSIGNED_SHORT, 0);
   glBindVertexArray(0);
   glUseProgram(0);
}

it will look like this


So good


Do you share to help advance the development of this technology, or just to show off?

Discord: z0lik

Offline hoanmaster #34 Posteado: July 22, 2025, 03:37:18 AM

  • 0 puntos por ventas
  • *
  • Rank: Dedicado
  • Posts: 31
  • Gracias recibida: 29
  • vn
void BMD::RenderVertexBuffer(int i, Mesh_t* m, int vertex_index, vec3_t* vertices, vec2_t* textCoords)
{
   GLuint shader_id = gShaderGL->GetShaderId();
   glUseProgram(shader_id);
    glm::mat4 model;
    for (int j = 0; j < m->NumVertices; j++)
   {
        Vertex_t* v = &m->Vertices[j];

        float* vp = VertexTransform[j];
        VectorTransform(v->Position, BoneMatrix[v->Node], vp);
       VectorRotate(v->Position, BoneMatrix[v->Node], vp);
      vp[0] = vp[0] * BoneScale + BoneMatrix[v->Node][0][3];
      vp[1] = vp[1] * BoneScale + BoneMatrix[v->Node][1][3];
      vp[2] = vp[2] * BoneScale + BoneMatrix[v->Node][2][3];
        model = glm::translate(glm::mat4(1.0f), vp);
               
    }

   glm::mat4 view = glm::lookAt(glm::vec3(-CameraPosition[0], -CameraPosition[1], -CameraPosition[2]), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
   glm::mat4 projection = glm::perspective(glm::radians(CameraFOV), (float)WindowWidth / (float)WindowHeight, CameraViewNear, CameraViewFar * 1.4f);

   glUniformMatrix4fv(glGetUniformLocation(shader_id, "projection"), 1, GL_FALSE, glm::value_ptr(projection));

   // Enviar la matriz de vista
   glUniformMatrix4fv(glGetUniformLocation(shader_id, "view"), 1, GL_FALSE, glm::value_ptr(view));

   // Enviar la matriz de modelo
   glUniformMatrix4fv(glGetUniformLocation(shader_id, "model"), 1, GL_FALSE, glm::value_ptr(model));


   glBindVertexArray(m->VAO);
   glDrawElements(GL_TRIANGLES, vertex_index, GL_UNSIGNED_SHORT, 0);
   glBindVertexArray(0);
   glUseProgram(0);
}

it will look like this



Do you share to help advance the development of this technology, or just to show off?
I thank my friend because looking at his code helped me do it (although it didn't work for me much), the code you shared itself can't render like the image you posted.


Offline xufqing #35 Posteado: July 27, 2025, 01:01:50 AM

  • 0 puntos por ventas
  • *
  • Rank: Dedicado
  • Posts: 32
  • Gracias recibida: 70
  • cn
After a period of research, I successfully passed the vertex data from OpenGL to the GPU. However, there is still some data in the main function that cannot be uploaded. My idea is to partially render on the CPU and partially on the GPU—for example, using TLS to determine whether the current frame should be processed by the CPU or GPU. Can someone give me some guidance?


Offline pnicacio #36 Posteado: August 03, 2025, 08:27:41 PM

  • 0 puntos por ventas
  • *
  • Rank: Principiante
  • Posts: 7
  • Gracias recibida: 0
  • br
After a period of research, I successfully passed the vertex data from OpenGL to the GPU. However, there is still some data in the main function that cannot be uploaded. My idea is to partially render on the CPU and partially on the GPU—for example, using TLS to determine whether the current frame should be processed by the CPU or GPU. Can someone give me some guidance?

Realmente pensei no Mesmo, até conseguir replicar o que foi Repassado pelo Takumi e por z0lik, consegui fazer os Ajustes da camera, mais eu não tive um grande desempenho consideravel em CPU's mais antigas.

Até comecei a Conversão total do Cliente usando o Glew32 para usar o OpenGL moderno nas Chamadas Gerais do Cliente.

Percebi que mesmo implementando, seria Nescessário Mudar completamente todas as Chamadas do RenderMesh, RenderBody, RenderBodyShadow.

Para funcionar é Nescessário Iniciar o CPP novo citado pelo Takumi, recriar os Arquivos .vs e .fs, Chamar na Função Open2 e em Seguida, alterar o Final do RenderMesh.


Offline xufqing #37 Posteado: August 03, 2025, 10:32:58 PM

  • 0 puntos por ventas
  • *
  • Rank: Dedicado
  • Posts: 32
  • Gracias recibida: 70
  • cn
After a period of research, I successfully passed the vertex data from OpenGL to the GPU. However, there is still some data in the main function that cannot be uploaded. My idea is to partially render on the CPU and partially on the GPU—for example, using TLS to determine whether the current frame should be processed by the CPU or GPU. Can someone give me some guidance?

Realmente pensei no Mesmo, até conseguir replicar o que foi Repassado pelo Takumi e por z0lik, consegui fazer os Ajustes da camera, mais eu não tive um grande desempenho consideravel em CPU's mais antigas.

Até comecei a Conversão total do Cliente usando o Glew32 para usar o OpenGL moderno nas Chamadas Gerais do Cliente.

Percebi que mesmo implementando, seria Nescessário Mudar completamente todas as Chamadas do RenderMesh, RenderBody, RenderBodyShadow.

Para funcionar é Nescessário Iniciar o CPP novo citado pelo Takumi, recriar os Arquivos .vs e .fs, Chamar na Função Open2 e em Seguida, alterar o Final do RenderMesh.
Now the entire RenderMesh is being passed to the GPU, without distinguishing between CPU and GPU. We've implemented effective optimization techniques such as VAO, VBO, EBO, and UBO. Unfortunately, as you mentioned, while this yields good performance on high-end graphics cards, the improvement is not significant on older GPUs, and there hasn't been much progress so far.



Offline Feche #38 Posteado: August 08, 2025, 01:15:58 PM

  • C++ Coder
  • 0 puntos por ventas
  • *
  • Rank: Dedicado
  • Posts: 57
  • Gracias recibida: 1719
  • ar
After a period of research, I successfully passed the vertex data from OpenGL to the GPU. However, there is still some data in the main function that cannot be uploaded. My idea is to partially render on the CPU and partially on the GPU—for example, using TLS to determine whether the current frame should be processed by the CPU or GPU. Can someone give me some guidance?

Realmente pensei no Mesmo, até conseguir replicar o que foi Repassado pelo Takumi e por z0lik, consegui fazer os Ajustes da camera, mais eu não tive um grande desempenho consideravel em CPU's mais antigas.

Até comecei a Conversão total do Cliente usando o Glew32 para usar o OpenGL moderno nas Chamadas Gerais do Cliente.

Percebi que mesmo implementando, seria Nescessário Mudar completamente todas as Chamadas do RenderMesh, RenderBody, RenderBodyShadow.

Para funcionar é Nescessário Iniciar o CPP novo citado pelo Takumi, recriar os Arquivos .vs e .fs, Chamar na Função Open2 e em Seguida, alterar o Final do RenderMesh.
Now the entire RenderMesh is being passed to the GPU, without distinguishing between CPU and GPU. We've implemented effective optimization techniques such as VAO, VBO, EBO, and UBO. Unfortunately, as you mentioned, while this yields good performance on high-end graphics cards, the improvement is not significant on older GPUs, and there hasn't been much progress so far.

The issue with this implementation is that all objects must be on a SINGLE VAO, right now it is binding -> rendering -> unbinding (this can be skipped) -> setting OGL program to 0 (this can be skipped too) - the right solution would be to use the single VAO, save all OGL states and render each object by using glDrawElementsBaseVertex.

If anyone is trying to make the shaders, I can share the one I made for OpenGL 2.0 - bone matrix, chrome effects and lighting is done on GPU.

Vertex shader


Fragment shader:


You then would need to send the data to the GPU:



Offline z0lik #39 Posteado: August 23, 2025, 03:28:09 AM

  • 0 puntos por ventas
  • *
  • Rank: Principiante
  • Posts: 7
  • Gracias recibida: 3
  • it
// This function is from 0.97d - so adjust according to your game version


AI?

Discord: z0lik

Offline ZabiinoOo #40 Posteado: September 18, 2025, 05:12:06 PM

  • MAESTRO

  • US. DE HONOR

  • LEYENDA

  • Administrador
  • 0 puntos por ventas
  • *
  • Rank: Puto amo
  • Posts: 7.470
  • Gracias recibida: 136950
  • pe
void BMD::RenderVertexBuffer(int i, Mesh_t* m, int vertex_index, vec3_t* vertices, vec2_t* textCoords)
{
   GLuint shader_id = gShaderGL->GetShaderId();
   glUseProgram(shader_id);
    glm::mat4 model;
    for (int j = 0; j < m->NumVertices; j++)
   {
        Vertex_t* v = &m->Vertices[j];

        float* vp = VertexTransform[j];
        VectorTransform(v->Position, BoneMatrix[v->Node], vp);
       VectorRotate(v->Position, BoneMatrix[v->Node], vp);
      vp[0] = vp[0] * BoneScale + BoneMatrix[v->Node][0][3];
      vp[1] = vp[1] * BoneScale + BoneMatrix[v->Node][1][3];
      vp[2] = vp[2] * BoneScale + BoneMatrix[v->Node][2][3];
        model = glm::translate(glm::mat4(1.0f), vp);
               
    }

   glm::mat4 view = glm::lookAt(glm::vec3(-CameraPosition[0], -CameraPosition[1], -CameraPosition[2]), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
   glm::mat4 projection = glm::perspective(glm::radians(CameraFOV), (float)WindowWidth / (float)WindowHeight, CameraViewNear, CameraViewFar * 1.4f);

   glUniformMatrix4fv(glGetUniformLocation(shader_id, "projection"), 1, GL_FALSE, glm::value_ptr(projection));

   // Enviar la matriz de vista
   glUniformMatrix4fv(glGetUniformLocation(shader_id, "view"), 1, GL_FALSE, glm::value_ptr(view));

   // Enviar la matriz de modelo
   glUniformMatrix4fv(glGetUniformLocation(shader_id, "model"), 1, GL_FALSE, glm::value_ptr(model));


   glBindVertexArray(m->VAO);
   glDrawElements(GL_TRIANGLES, vertex_index, GL_UNSIGNED_SHORT, 0);
   glBindVertexArray(0);
   glUseProgram(0);
}

it will look like this
How to implement in the renderMesh and other renders?


Eu hein ? O_O Rafael Dias pedindo ajuda na TuServerMU ? Eu estou vendo isso mesmo ? Aqui não era a Cracolandia do MU e você não precisava de nada de forum ?
Mundo gira hem..., porque não usa seu nome verdadeiro.... vergonha... retaliação ...

Falta humildade..... EU HEINNNN !



What the hell? O_O Rafael Dias asking for help on TuServerMU? Am I really seeing this? Wasn't this the MU's Crackland and you didn't need any forums?

Fra mundo huh..., why don't you use your real name.... shame... retaliation...

Lack of humility..... WHAT THE HELL!!

Assim são os amigos falsos e covardes, eles se escondem




Prohibido pedir soporte via MP
Leer las reglas de cada seccion
we trust god

Gracias:


Offline komandirbk #41 Posteado: October 07, 2025, 01:28:39 AM

  • 0 puntos por ventas
  • *
  • Rank: Usuario activo
  • Posts: 60
  • Gracias recibida: 317
  • ua


Code: [Select]
static GLuint EnsureVAOShader() {
if (gVAOProg) return gVAOProg;

const char* vsSrc =
"#version 120\n"
"attribute vec3 aPos;\n"
"attribute vec2 aTex;\n"
"attribute vec3 aCol;\n"
"varying vec2 vUV;\n"
"varying vec3 vCol;\n"
"uniform mat4 view, projection;\n"
"uniform int  uHasShift;\n"
"uniform float uShiftU, uShiftV;\n"
"uniform int  uUseColors;\n"
"void main(){\n"
"  gl_Position = projection * view * vec4(aPos,1.0);\n"
"  vUV = aTex;\n"
"  if(uHasShift==1){ vUV.x += uShiftU; vUV.y += uShiftV; }\n"
"  vCol = (uUseColors!=0) ? clamp(aCol,0.0,1.0) : vec3(1.0);\n"
"}\n";

// uMode: 0=base(textured), 1=bright(masked by texture alpha), 2=dark(subtractive), 3=bright(solid, no texture)
const char* fsSrc =
"#version 120\n"
"varying vec2 vUV;\n"
"varying vec3 vCol;\n"
"uniform sampler2D texture1;\n"
"uniform float Alpha;\n"
"uniform int   uMode;\n"
"uniform vec3  uBodyLight;\n"
"uniform float uBrightScale;\n"
"uniform float uAlphaCut;\n"
"void main(){\n"
"  if (uMode==3) {\n"
"    // BRIGHT solid: вообще не семплим текстуру\n"
"    gl_FragColor = vec4(uBodyLight * uBrightScale, 1.0);\n"
"    return;\n"
"  }\n"
"  vec4 t = texture2D(texture1, vUV);\n"
"  if (uMode==1) {\n"
"    // BRIGHT masked по альфе текстуры\n"
"    if (t.a <= uAlphaCut) discard;\n"
"    vec3 col = t.rgb * uBodyLight * uBrightScale * t.a;\n"
"    gl_FragColor = vec4(col, 1.0);\n"
"  } else if (uMode==2) {\n"
"    // DARK (subtractive). Альфа в базовом FFP не всегда влияла, оставим как есть\n"
"    gl_FragColor = vec4(t.rgb, t.a * Alpha);\n"
"  } else {\n"
"    // BASE textured\n"
"    if (t.a <= uAlphaCut) discard;\n"
"    gl_FragColor = vec4(t.rgb * vCol, t.a * Alpha);\n"
"  }\n"
"}\n";

GLuint vs = CompileGLSL(GL_VERTEX_SHADER, vsSrc);
GLuint fs = CompileGLSL(GL_FRAGMENT_SHADER, fsSrc);
gVAOProg = LinkProgram(vs, fs, "aPos", "aTex", "aCol");
return gVAOProg;
}

The only one place where i call func now it's :
Code: [Select]
void BMD::RenderMesh(int meshIndex, int renderFlags, float alpha, int blendMeshIndex, float blendMeshAlpha, float blendMeshTextureCoordU, float blendMeshTextureCoordV, int explicitTextureIndex)
{


#ifdef USE_VAO
if ((renderFlags & RENDER_TEXTURE) == RENDER_TEXTURE) {
RenderMesh_VAO(meshIndex, renderFlags, alpha,
blendMeshIndex, blendMeshAlpha,
blendMeshTextureCoordU, blendMeshTextureCoordV,
explicitTextureIndex);
return;
}
#endif



if (meshIndex >= NumMeshs || meshIndex < 0) return;
Mesh_t* m = &Meshs[meshIndex];
if (m->NumTriangles == 0) return;


Tell me guys, which functions I need to replace to make this VAO works great ?

Code: [Select]
void BMD::RenderMesh_VAO(int i,
int renderFlags, float alpha,
int /*blendMeshIndex*/, float blendMeshLight,
float blendMeshTexCoordU, float blendMeshTexCoordV,
int explicitTextureIndex)
{
if (i < 0 || i >= NumMeshs) return;
Mesh_t* m = &Meshs[i];
if (m->NumTriangles <= 0) return;

UpdateMeshVAO(i, *m);

GLStateGuard guard; guard.capture();
GLMini_Log("AFTER_CLEAN", i, renderFlags, -1, -1, alpha,
BodyLight[0], BodyLight[1], BodyLight[2]);

int tex = (explicitTextureIndex != -1) ? explicitTextureIndex : IndexTexture[m->Texture];
if (tex == BITMAP_HIDE) { guard.restore(); return; }
if (tex == BITMAP_SKIN) { if (HideSkin) { guard.restore(); return; } tex = BITMAP_SKIN + Skin; }
BindTexture(tex);


glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

GLuint prog = GetVAOShader();
glUseProgram(prog);

GLfloat mv[16], pr[16];
glGetFloatv(GL_MODELVIEW_MATRIX, mv);
glGetFloatv(GL_PROJECTION_MATRIX, pr);
glUniformMatrix4fv(glGetUniformLocation(prog, "view"), 1, GL_FALSE, mv);
glUniformMatrix4fv(glGetUniformLocation(prog, "projection"), 1, GL_FALSE, pr);

const int hasShift =
((renderFlags & RENDER_TEXTURE) &&
(blendMeshTexCoordU != 0.f || blendMeshTexCoordV != 0.f)) ? 1 : 0;
glUniform1i(glGetUniformLocation(prog, "uHasShift"), hasShift);
glUniform1f(glGetUniformLocation(prog, "uShiftU"), blendMeshTexCoordU);
glUniform1f(glGetUniformLocation(prog, "uShiftV"), blendMeshTexCoordV);

glUniform1i(glGetUniformLocation(prog, "texture1"), 0);
glUniform1f(glGetUniformLocation(prog, "Alpha"), alpha);

const int hasSpecialColor =
(renderFlags & (RENDER_COLOR | RENDER_CHROME | RENDER_OIL)) != 0;
const int isWorldBase =
((renderFlags & RENDER_TEXTURE) != 0) && !hasSpecialColor;
const int useColors = isWorldBase ? 0 : ((LightEnable != 0) ? 1 : 0);
glUniform1i(glGetUniformLocation(prog, "uUseColors"), useColors);

const bool nodepth = (renderFlags & RENDER_NODEPTH) != 0;
if (nodepth) glDisable(GL_DEPTH_TEST); else glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);

const bool wantsBright = (renderFlags & RENDER_BRIGHT) != 0;
const bool wantsDark = (renderFlags & RENDER_DARK) != 0;

glBindVertexArray(m->VAO);

// ===== BASE PASS =====
if (!wantsBright) {
glDisable(GL_BLEND);
if (alpha < 0.999f) {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
glUniform1i(glGetUniformLocation(prog, "uMode"), 0);
glUniform1f(glGetUniformLocation(prog, "uAlphaCut"), 0.25f);
GLMini_Log("BASE", i, renderFlags, 0, useColors, alpha,
BodyLight[0], BodyLight[1], BodyLight[2]);
glDrawElements(GL_TRIANGLES, m->drawIndexCount, GL_UNSIGNED_SHORT, (void*)0);
}
else {
GLMini_Log("SKIP_BASE_BRIGHT", i, renderFlags, 0, useColors, alpha,
BodyLight[0], BodyLight[1], BodyLight[2]);
}

// ===== BRIGHT (additive) =====
if (wantsBright) {
glDepthMask(GL_FALSE);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE);
glUniform1i(glGetUniformLocation(prog, "uMode"), 1);
glUniform1f(glGetUniformLocation(prog, "uBrightScale"),
(blendMeshLight > 0.f ? blendMeshLight : 1.f));
glUniform3f(glGetUniformLocation(prog, "uBodyLight"),
clamp01f(BodyLight[0]), clamp01f(BodyLight[1]), clamp01f(BodyLight[2]));
glUniform1f(glGetUniformLocation(prog, "uAlphaCut"), 0.01f);
GLMini_Log("BRIGHT", i, renderFlags, 1, useColors, alpha,
BodyLight[0], BodyLight[1], BodyLight[2]);
glDrawElements(GL_TRIANGLES, m->drawIndexCount, GL_UNSIGNED_SHORT, (void*)0);
glDepthMask(GL_TRUE);
}

// ===== DARK (subtractive) =====
if (wantsDark) {
glEnable(GL_BLEND);
glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_COLOR);
glUniform1i(glGetUniformLocation(prog, "uMode"), 2);
glUniform1f(glGetUniformLocation(prog, "uAlphaCut"), 0.0f);
GLMini_Log("DARK", i, renderFlags, 2, useColors, alpha,
BodyLight[0], BodyLight[1], BodyLight[2]);
glDrawElements(GL_TRIANGLES, m->drawIndexCount, GL_UNSIGNED_SHORT, (void*)0);
}

glBindVertexArray(0);
glDisable(GL_BLEND);
glUseProgram(0);
guard.restore();
}

Code: [Select]
void BMD::UpdateMeshVAO(int meshIndex, Mesh_t& m)
{
if (!m.gpuReady) BuildMeshVAO(meshIndex, m);

const size_t N = m.remapV.size();
const int useLight = (LightEnable != 0); // включён ли пер-вершинный свет

for (size_t i = 0; i < N; ++i)
{
const int sv = m.remapV[i];
const size_t base = i * 3;

// позиции — из анимированных вершин
m.cpuPositions[base + 0] = VertexTransform[meshIndex][sv][0];
m.cpuPositions[base + 1] = VertexTransform[meshIndex][sv][1];
m.cpuPositions[base + 2] = VertexTransform[meshIndex][sv][2];

// цвет вершины — ТОЛЬКО LightTransform при включенном лайтинге
float r = 1.f, g = 1.f, b = 1.f;
if (useLight) {
const int sn = m.remapN[i];
r = LightTransform[meshIndex][sn][0];
g = LightTransform[meshIndex][sn][1];
b = LightTransform[meshIndex][sn][2];

// возможный диапазон 0..255 — нормализуем
if (r > 1.f || g > 1.f || b > 1.f) {
r *= (1.f / 255.f);
g *= (1.f / 255.f);
b *= (1.f / 255.f);
}

// защита от NaN/мусора
if (!(r == r)) r = 1.f;
if (!(g == g)) g = 1.f;
if (!(b == b)) b = 1.f;

// мягкий clamp
r = clamp01f(r); g = clamp01f(g); b = clamp01f(b);
}

m.cpuColors[base + 0] = r;
m.cpuColors[base + 1] = g;
m.cpuColors[base + 2] = b;
}

glBindBuffer(GL_ARRAY_BUFFER, m.VBO_Vertices);
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(float) * 3 * N, m.cpuPositions.data());

glBindBuffer(GL_ARRAY_BUFFER, m.VBO_Colors);
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(float) * 3 * N, m.cpuColors.data());
}

Code: [Select]
void BMD::BuildMeshVAO(int meshIndex, Mesh_t& m)
{
if (m.gpuReady) return;

m.indices.clear();
m.remapV.clear();
m.remapN.clear();
m.remapT.clear();
m.cpuUVs.clear();

m.indices.reserve(m.NumTriangles * 3);
m.remapV.reserve(m.NumTriangles * 3);
m.remapN.reserve(m.NumTriangles * 3);
m.remapT.reserve(m.NumTriangles * 3);
m.cpuUVs.reserve(m.NumTriangles * 3);

for (int t = 0; t < m.NumTriangles; ++t) {
const Triangle_t& tri = m.Triangles[t];
// MU-модели тут треугольники — берём первые 3 индекса
for (int k = 0; k < 3; ++k) {
const int sv = tri.VertexIndex[k];
const int sn = tri.NormalIndex[k];
const int st = tri.TexCoordIndex[k];

m.remapV.push_back((unsigned short)sv);
m.remapN.push_back((unsigned short)sn);
m.remapT.push_back((unsigned short)st);
m.cpuUVs.push_back(m.TexCoords[st]);

m.indices.push_back((unsigned short)m.indices.size());
}
}

const size_t N = m.remapV.size();
m.drawVertexCount = (GLsizei)N;
m.drawIndexCount = (int)N;

m.cpuPositions.resize(N * 3);
m.cpuColors.resize(N * 3);

glGenVertexArrays(1, &m.VAO);
glBindVertexArray(m.VAO);

// позиции
glGenBuffers(1, &m.VBO_Vertices);
glBindBuffer(GL_ARRAY_BUFFER, m.VBO_Vertices);
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 3 * N, 0, GL_DYNAMIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);

// цвета
glGenBuffers(1, &m.VBO_Colors);
glBindBuffer(GL_ARRAY_BUFFER, m.VBO_Colors);
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 3 * N, 0, GL_DYNAMIC_DRAW);
glEnableVertexAttribArray(3);
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);

// UV
glGenBuffers(1, &m.VBO_TexCoords);
glBindBuffer(GL_ARRAY_BUFFER, m.VBO_TexCoords);
glBufferData(GL_ARRAY_BUFFER, sizeof(TexCoord_t) * N, m.cpuUVs.data(), GL_STATIC_DRAW);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(TexCoord_t), (void*)0);

// индексы
glGenBuffers(1, &m.EBO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m.EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned short) * N, m.indices.data(), GL_STATIC_DRAW);

glBindVertexArray(0);
m.gpuReady = true;
}

Code: [Select]
// ===== Guard для GL-состояний, чтобы VAO не ломал FFP =======================
struct GLStateGuard {
GLboolean blend, alpha, depth, depthMask;
GLint     src, dst;
GLint     activeTex;
GLboolean tex2D0;
GLint     texEnv0;

void capture() {
blend = glIsEnabled(GL_BLEND);
alpha = glIsEnabled(GL_ALPHA_TEST);
depth = glIsEnabled(GL_DEPTH_TEST);
glGetBooleanv(GL_DEPTH_WRITEMASK, &depthMask);
glGetIntegerv(GL_BLEND_SRC, &src);
glGetIntegerv(GL_BLEND_DST, &dst);
glGetIntegerv(GL_ACTIVE_TEXTURE, &activeTex);
glActiveTexture(GL_TEXTURE0);
tex2D0 = glIsEnabled(GL_TEXTURE_2D);
glGetTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &texEnv0);
glActiveTexture(activeTex);
}

void restore() {
if (blend) glEnable(GL_BLEND); else glDisable(GL_BLEND);
if (alpha) glEnable(GL_ALPHA_TEST); else glDisable(GL_ALPHA_TEST);
if (depth) glEnable(GL_DEPTH_TEST); else glDisable(GL_DEPTH_TEST);
glDepthMask(depthMask);
glBlendFunc(src, dst);
GLint was = 0; glGetIntegerv(GL_ACTIVE_TEXTURE, &was);
glActiveTexture(GL_TEXTURE0);
if (tex2D0) glEnable(GL_TEXTURE_2D); else glDisable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, texEnv0);
glActiveTexture(was);
}
};



// ZzzBMD.cpp
static void CleanFixedStatesForShader()
{
glDisable(GL_LIGHTING);
glDisable(GL_COLOR_MATERIAL);
glDisable(GL_FOG);


glDisable(GL_ALPHA_TEST);


glDisable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);


glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);


GLint maxTU = 0;
glGetIntegerv(GL_MAX_TEXTURE_UNITS, &maxTU);
for (int u = 0; u < maxTU; ++u) {
glActiveTexture(GL_TEXTURE0 + u);
if (u == 0) glEnable(GL_TEXTURE_2D); else glDisable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
}
glActiveTexture(GL_TEXTURE0);
}

What I am doing wrong? @takumi12

Discord: brain_off

Gracias:


Offline z0lik #42 Posteado: October 07, 2025, 05:00:52 AM

  • 0 puntos por ventas
  • *
  • Rank: Principiante
  • Posts: 7
  • Gracias recibida: 3
  • it
What exactly, is it not working?, is it dropping fps? or is it not rendering all the triangles?

Discord: z0lik

Solo usuarios registrados pueden comentar y agradecer, Logueate o Registrate


 

Related Topics

  Subject / Started by Replies Last post
4 Replies
5580 Views
Last post March 03, 2020, 05:27:28 PM
by jorginhuz
4 Replies
2042 Views
Last post March 02, 2025, 08:12:33 PM
by czrdiamond
33 Replies
8726 Views
Last post November 14, 2021, 03:43:48 PM
by jorge2016
27 Replies
12543 Views
Last post April 06, 2025, 06:00:54 AM
by Xingaw
8 Replies
6083 Views
Last post June 03, 2024, 11:47:23 PM
by Kosh