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 4612148
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:21:52+00:00 2026-05-22T01:21:52+00:00

What would be the best algorithm to generate a list of vertices to draw

  • 0

What would be the best algorithm to generate a list of vertices to draw a plane using triangle strips?

I’m looking for a function which receives the plane’s width and height and returns a float array containing correctly indexed vertices.

width represents the number of vertices per row.

height represents the number of vertices per column.

float* getVertices( int width, int height ) {
    ...
}

void render() {
    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(3, GL_FLOAT, 0, getVertices(width,heigth));
    glDrawArrays(GL_TRIANGLE_STRIP, 0, width*height);
    glDisableClientState(GL_VERTEX_ARRAY);
}
  • 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-05-22T01:21:53+00:00Added an answer on May 22, 2026 at 1:21 am

    Thanks you all. I’ve coded this. Is it correct? Or is the generated strip somehow wrong?

    int width;
    int height;
    float* vertices = 0;
    int* indices = 0;
    
    int getVerticesCount( int width, int height ) {
        return width * height * 3;
    }
    
    int getIndicesCount( int width, int height ) {
        return (width*height) + (width-1)*(height-2);
    }
    
    float* getVertices( int width, int height ) {
        if ( vertices ) return vertices;
    
        vertices = new float[ getVerticesCount( width, height ) ];
        int i = 0;
    
        for ( int row=0; row<height; row++ ) {
            for ( int col=0; col<width; col++ ) {
                vertices[i++] = (float) col;
                vertices[i++] = 0.0f;
                vertices[i++] = (float) row;
            }
        }
    
        return vertices;
    }
    
    int* getIndices( int width, int height ) {
        if ( indices ) return indices;
    
        indices = new int[ iSize ];
        int i = 0;
    
        for ( int row=0; row<height-1; row++ ) {
            if ( (row&1)==0 ) { // even rows
                for ( int col=0; col<width; col++ ) {
                    indices[i++] = col + row * width;
                    indices[i++] = col + (row+1) * width;
                }
            } else { // odd rows
                for ( int col=width-1; col>0; col-- ) {
                    indices[i++] = col + (row+1) * width;
                    indices[i++] = col - 1 + + row * width;
                }
            }
        }
        if ( (mHeight&1) && mHeight>2 ) {
            mpIndices[i++] = (mHeight-1) * mWidth;
        }
    
        return indices;
    }
    
    void render() {
        glEnableClientState( GL_VERTEX_ARRAY );
        glVertexPointer( 3, GL_FLOAT, 0, getVertices(width,height) );
        glDrawElements( GL_TRIANGLE_STRIP, getIndicesCount(width,height), GL_UNSIGNED_INT, getIndices(width,height) );
        glDisableClientState( GL_VERTEX_ARRAY );
    }
    

    With width=4 and height=4 this is what I got:
    enter image description here

    And here I’m modifying some vertex height:
    enter image description here

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

Sidebar

Related Questions

What would be the best algorithm for finding a number that occurs only once
What would be the best algorithm to solve this problem? I spent a couple
What would be the best hashing algorithm if we had the following priorities (in
What would be the best compression algorithm to use to compress packets before sending
I wanted to know which would be best suitable - EDM or reflection provider
What would be the best algorithm / code to convert time to float? I'm
I am looking for an algorithm, preferably in Python that would help me locate
I have an algorithm that operates on an IntMap that I feel would best
When requesting hardware for a WebLogic server, what hardware would best improve its performance?
Best would be if it performs the highlighting exactly as it is in Visual

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.