Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8224079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:55:56+00:00 2026-06-07T14:55:56+00:00

My render method currently looks like this: void Renderer::render() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); checkGlError(glClear);

  • 0

My render method currently looks like this:

void Renderer::render() {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    checkGlError("glClear");

    EntityCamera* camera = (EntityCamera*) resourceManager_->getResource(GHOST_CAMERA);

    mat4 proj;
    Matrix::projection3D(proj, 45.0f,
            (float) nScreenWidth_ / nScreenHeight_, GHOST_NEAR_DISTANCE, GHOST_FAR_DISTANCE);

    mat4 view;
    Matrix::multiply(proj, camera_->getMatrix(), view);
    camera->extractPlanes(view);

    for (vector<Node*>::const_iterator it = renderArray_.begin(); it != renderArray_.end();
            it++) {
        Node* node = *it;
        if (!node->isRenderable()) {
            continue;
        }
        if (node->hasBV() && node->getBV()->isInFrustum(camera, node) == BoundingVolume::OUTSIDE) {
            LOGI("Node %s is outside :O", node->getName().c_str());
            continue;
        }
        EntityModel* entity =
                static_cast<EntityModel*>(resourceManager_->getResource(
                        (*it)->getEntity()));
        if (entity == 0 || entity->getVertices() == 0 || entity->getVertices()->size() == 0) {
            LOGI("Empty entity %s.", node->getName().c_str());
            continue;
        }
        Resource* resource = resourceManager_->getResource(node->getShader());
        Shader* shader = static_cast<Shader*>(resource);
        Resource* resource2 = resourceManager_->getResource(entity->getTexture());
        Image* image = static_cast<Image*>(resource2);
        mat4 res;
        Matrix::multiply(view, node->getMatrix(), res);

        // Select shader program to use.
        glUseProgram(shader->getId());
        checkGlError("glUseProgram");

        int matrix = glGetUniformLocation(shader->getId(), "uWVP");
        int texture = glGetUniformLocation(shader->getId(), "texture_0");
        checkGlError("glGetUniformLocation");
        int textureCoords = glGetAttribLocation(shader->getId(), "attrTexCoords");
        int vertices = glGetAttribLocation(shader->getId(), "attrPos");
        checkGlError("glGetAttribLocation");

        // Specify WVP matrix.
        glUniformMatrix4fv(matrix, 1, false, res);
        checkGlError("glUniformMatrix4fv");

        // Load vertex positions.
        if (!entity->isCompiled()) {
            //LOGI("Entity %s, not compiled.", entity->getName().c_str());
            continue;
        }
        glEnableVertexAttribArray(vertices);
        checkGlError("glEnableVertexAttribArray");
        //glVertexAttribPointer(vertices, 3, GL_FLOAT, GL_FALSE, 0,
        //      &(*entity->getVertices())[0]);
        //LOGI("%s vbo id: %d", node->getName().c_str(), entity->getVBO());
        glBindBuffer(GL_ARRAY_BUFFER, entity->getVBO());
        checkGlError("glBindBuffer");
        glVertexAttribPointer(vertices, 3, GL_FLOAT, GL_FALSE, 0, 0);
        checkGlError("glVertexAttribPointer");
        // Load UV coordinates.
        glEnableVertexAttribArray(textureCoords);
        checkGlError("glEnableVertexAttribArray");
        glVertexAttribPointer(textureCoords, 2, GL_FLOAT, GL_FALSE, 0,
                &(*entity->getTextureCoords())[0]);
        checkGlError("glVertexAttribPointer");

        // Bind the texture.
        glActiveTexture(GL_TEXTURE0);
        checkGlError("glActiveTexture");
        glBindTexture(GL_TEXTURE_2D, image->getId());
        checkGlError("glBindTexture");
        glUniform1i(texture, 0);
        checkGlError("glUniform1i");

        if (entity->hasIndices()) {
            vector<vector<GLushort>*>* indices = entity->getIndices();
            for (unsigned int i = 0; i < indices->size(); i++) {
                if (entity->hasBoundingVolumes()) {
                    BoundingVolume* volume = (*entity->getBoundingVolumes())[i];
                    if (volume->isInFrustum(camera, node) == BoundingVolume::OUTSIDE) {
                        continue;
                    }
                }
                vector<GLushort>* ind = (*indices)[i];
                glDrawElements(GL_TRIANGLES, ind->size(), GL_UNSIGNED_SHORT, &(*ind)[0]);
                checkGlError("glDrawElements");
            }
        }
        else {
            glDrawArrays(GL_TRIANGLES, 0, entity->getVertices()->size() / 3);
            checkGlError("glDrawArrays");
        }
        glBindBuffer(GL_ARRAY_BUFFER, 0);
        checkGlError("glBindBuffer");
    }
}

I just recently tried to use VBO, before I was sending vertex data directly and everything worked fine, textures were mapped correctly. Now I changed vertex array with VBO and even though it works, no textures are applied, I could only see black object.


  1. What might be wrong with my textures?
  2. Why when I change glVertexAttribPointer(vertices, 3, GL_FLOAT, GL_FALSE, 0, 0); line order with glBindBuffer(GL_ARRAY_BUFFER, entity->getVBO()); I get disfigured objects? Is this the right call order that I’m using?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T14:55:58+00:00Added an answer on June 7, 2026 at 2:55 pm

    You’re sending your UV coordinates from plain memory, while you seem to send your vertex coordinates from a VBO. This may not be so efficient, you should have both data sets in VBO to profit of the VBO advantages.

    That being said, I think your problem is that you don’t unbind your VBO before sending your UV coordinates. Your code should be :

    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glVertexAttribPointer(textureCoords, 2, GL_FLOAT, GL_FALSE, 0,
                &(*entity->getTextureCoords())[0]);
    

    as I suppose your getTextureCoords() does not return an offset in your VBO.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method that gets rows from my database. It looks like this:
Im currently using a method that looks like the following code to add script
i have the following method in a usercontrol protected override void Render(HtmlTextWriter writer) {
I am getting the error: object render has no method apply for the below
I have a CATiledLayer into which I render content in the following method -
another django question. I have a edit form like this. Look at current_status in
I have some data which I am formatting like this: // ... imagine populating
Hi, I'm a Rails newbie and this is my first stackoverflow question. I'm currently
Something like Textile for the posts feels pretty necessary, but this is giving me
The 'reader' within the if statement is showing Expression is not a method Dim

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.