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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:38:30+00:00 2026-05-11T07:38:30+00:00

I’m trying to convert the following code from OpenGL 1.5 spec. to the OpenGLES

  • 0

I’m trying to convert the following code from OpenGL 1.5 spec. to the OpenGLES 1.1 spec

(num_x and num_y are passed into the function by arguments)  ::glBegin(GL_LINES); for (int i=-num_x; i<=num_x; i++)  {     glVertex3i(i, 0, -num_y);     glVertex3i(i, 0,  num_y);  }  for (int i=-num_y; i<=num_y; i++)  {     glVertex3i(-num_x, 0, i);     glVertex3i( num_x, 0, i); }  ::glEnd(); 

Here is my corresponding converted code: (ignore the inefficiency of my loops, I am trying to get the conversion to work properly first)

I’m trying to build two things here:

  • A float array of all the x,y,z coordinates needed to draw the grid
  • An index array of all the verticies needed.
  • Both arrays are then passed to OpenGL which renders them.

An example of what the arrays should look like:

GLshort indices[] = {3, 0, 1, 2,                       3, 3, 4, 5,                       3, 6, 7, 8, }; GLfloat vertexs[] = {3.0f, 0.0f, 0.0f,                      6.0f, 0.0f, -0.5f ,                      0,    0,     0,                      6.0f, 0.0f,  0.5f,                      3.0f, 0.0f,  0.0f,                      0,    0,     0,                      3,    0,     0,                      0,    0,     0,                      0,    6,     0}; 

int iNumOfVerticies = (num_x + num_y)*4*3; int iNumOfIndicies = (iNumOfVerticies/3)*4;  GLshort* verticies = new short[iNumOfVerticies]; GLshort* indicies = new short[iNumOfIndicies]; int j = 0; for(int i=-num_x; j < iNumOfVerticies &&  i<=num_x; i++,j+=6) {     verticies[j] = i;     verticies[j+1] = 0;     verticies[j+2] = -num_y;      verticies[j+3] = i;     verticies[j+4] = 0;     verticies[j+5] = num_y;  }   for(int i=-num_y; j < iNumOfVerticies && i<=num_y;i++,j+=6)  {      verticies[j] = i;      verticies[j+1] = 0;      verticies[j+2] = -num_x;       verticies[j+3] = i;      verticies[j+4] = 0;      verticies[j+5] = num_x;  } 

I need to also build an array if indicies to pass on. I ‘borrowed’ the array structure from the iphone ‘teapot’ example.

In each row, we have the number of indicies followed by the indicies referenced.

 int k = 0;  for(j = 0; j < iNumOfIndicies; j++)  {       if (j%4==0)       {          indicies[j] = 3;       }       else       {          indicies[j] = k++;       }   }  ::glEnableClientState(GL_VERTEX_ARRAY);  ::glVertexPointer(3 ,GL_FLOAT, 0, verticies);   for(int i = 0; i < iNumOfIndicies;i += indicies[i] + 1)  {        ::glDrawElements(  GL_LINES, indicies[i], GL_UNSIGNED_SHORT, &indicies[i+1] );  }   delete [] verticies;  delete [] indicies; 

Please add code questions as comments, not answers

  • 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. 2026-05-11T07:38:30+00:00Added an answer on May 11, 2026 at 7:38 am

    I can see several things wrong with your converted code:

    1.- Using the wrong type for the variable verticies, it should be:

    GLfloat* verticies = new float[iNumOfVerticies]; 

    2.- Incorrectly filling verticies, second loop should be:

    for(int i=-num_y; j < iNumOfVerticies && i<=num_y;i++,j+=6) {     verticies[j] = -num_x;     verticies[j+1] = 0;     verticies[j+2] = i;      verticies[j+3] = num_x;     verticies[j+4] = 0;     verticies[j+5] = i; } 

    3.- Incorrect filling of indicies, I think you should delete the lines:

    if (j%4==0) {      indicies[j] = 3; } else 

    4.- Incorrect use of glDrawElements, replace the loop by this single line:

    ::glDrawElements(  GL_LINES, iNumOfIndicies, GL_UNSIGNED_SHORT, indicies); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 77k
  • Answers 77k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Update: (after the comment on it not being linq2sql) In… May 11, 2026 at 3:18 pm
  • added an answer I found the following document on Experts Exchange. patrikt: You… May 11, 2026 at 3:18 pm
  • added an answer It should be a pretty simple matter to remove the… May 11, 2026 at 3:18 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.