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

  • Home
  • SEARCH
  • 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 8743987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:46:20+00:00 2026-06-13T11:46:20+00:00

I am working on a n-body code with glut functions display. I would like

  • 0

I am working on a n-body code with “glut functions” display. I would like to display each body with a 2D texture from a bmp image. Currently, I can draw a single textured element with the following code :

 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);// Clear The Screen And The Depth Buffer

        glBindTexture(GL_TEXTURE_2D, texture[0]);    // pick the texture.
        glBegin(GL_QUADS); // begin drawing the textured quad.
        glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 0.0f);
        glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 0.0f);
        glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, 0.0f);
        glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 0.0f);
        glEnd(); // done drawing the textured quad.

In the first version of my code, I draw the positions of each body with the following display function :

void drawPoints()
{       
        GLuint vbo;

        glBindBuffer(GL_ARRAY_BUFFER, vbo);
        glVertexPointer(4, GL_DOUBLE, 4*sizeof(double), pos);   
        glEnableClientState(GL_VERTEX_ARRAY);

        if (colorVBO) {
            glBindBuffer(GL_ARRAY_BUFFER, id_colorVBO);
            glColorPointer(4, GL_DOUBLE, 4*sizeof(double), pos);
            glEnableClientState(GL_COLOR_ARRAY);
            glEnable(GL_BLEND);
            glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        }

        glColor3f(1, 1, 0);
        glDrawArrays(GL_POINTS, 0, numBodies);

        glBindBuffer(GL_ARRAY_BUFFER, 0);
        glDisableClientState(GL_VERTEX_ARRAY);
        glDisableClientState(GL_COLOR_ARRAY);
}

where pos array contains the coordinates x, y, z of each body. I am using glDrawArrays function to draw all the points at the same time.

Could you tell me how to plot all the textured elements and not only one, i.e a way to use the coordinates pos array for indicate the positions of all the textured bodies and draw them.

Updated :

ok, I try to use glTexCoordPointer with the following display function :

void drawPoints()
{       
    glPushMatrix();

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);// Clear The Screen And The Depth Buffer
    glBindTexture(GL_TEXTURE_2D, texture[0]);    // pick the texture.
    glLoadIdentity(); // reset the view before we draw each star.
    glTranslatef(0.0f, 0.0f, zoom);    // zoom into the screen. 

    glEnableClientState(GL_VERTEX_ARRAY);
    lEnableClientState(GL_TEXTURE_COORD_ARRAY);

    glVertexPointer(4, GL_DOUBLE, 4*sizeof(double), pos);   
    glTexCoordPointer(4, GL_DOUBLE, 4*sizeof(double), pos);

    // Assign A Color Using Bytes
    glColor4ub(30, 100, 120, 255);
    glBegin(GL_QUADS);  // Begin Drawing The Textured Quad
    glTexCoord2f(0.0f, 0.0f);  glVertex3f(-1.0f,-1.0f, 0.0f);
    glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,-1.0f, 0.0f);
    glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 0.0f);
    glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 0.0f);
    glEnd();   // Done Drawing The Textured Quad

    glDrawArrays(GL_QUADS, 0, numBodies);           
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);   
    glDisableClientState(GL_VERTEX_ARRAY);  

    glPopMatrix();  
}

but only one textured element is displayed.

Anyone sees what’s wrong ?

  • 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-13T11:46:21+00:00Added an answer on June 13, 2026 at 11:46 am

    In addition to glVertexPointer, you should use glTexCoordPointer. Do not forget to enable the corresponding client state, GL_TEXTURE_COORD_ARRAY. There is also a complete example on the official wiki, with interleaved attributes.

    Note that the new (3.0+) way is to use glVertexAttribPointer along with shaders. There’s a very descriptive page on the wiki on that, as well.

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

Sidebar

Related Questions

Can anyone tell me why this code would not be working? $('body').on('test', function() {
This javascript code is working fine. function goToByScroll(id){ $('html,body').animate({scrollTop: $(#+id).offset().top - 50},'slow'); } I'm
I downloaded http://code.google.com/chrome/extensions/samples.html#ea2894c41cb8e80a4433a3e6c5772dadce9be90d . I would like make it it jQuery, but if i
Following is my code can Any body please tell me why it is not
my code was working and taking my text from textbox to next page +
Hello every body I have used following code in my jpa project for working
following is my code working well in chrome. <body> <a href=javascript: sam.save();>hehe</a> <script> var
My code was working when <!DOCTYPE html> <html> <body style=position:fixed; top:0px; left:0px;bottom:0px; right:0px; margin:0px;>
This example working great because here containment is body http://jsfiddle.net/roXon/hMmbK/2/ when i use container
I'm working on a design that calls for the main body of the design

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.