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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:26:36+00:00 2026-05-26T04:26:36+00:00

I have 4 dimensional vertices(X,Y,A,B) that I’d like to draw as 6 separate 2D

  • 0

I have 4 dimensional vertices(X,Y,A,B) that I’d like to draw as 6 separate 2D plots (XxY, XxA, XxB, YxA, …)

My vertices are defined as follows:

GLint data[MAX_N_POINT][4];

I can draw the first (X,Y) of the 2D plots just fine with:

glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(4, GL_INT, 4*sizeof(GLint), &data[0][0]);

glDrawArrays(GL_POINTS, 0, MAX_N_POINT-1);
glDisableclientState(GL_VERTEX_ARRAY);

To draw the other 2D plots (XxA, AxB, etc…) I’ve decided to use a shader that swizzles the X,Y,Z,W dimensions of the vertices depending on which dimensions I want to draw.:

uniform int axes;

void main()
{

vec2 point;
if (axes == 0) {
   point = gl_Vertex.xy;
} else if (axes == 1) {
   point = gl_Vertex.xz;
} else if (axes == 2) {
   point = gl_Vertex.xw;
} else if (axes == 3) {
   point = gl_Vertex.yz;
} else if (axes == 4) {
   point = gl_Vertex.yw;
} else if (axes == 5) {
   point = gl_Vertex.zw;
}

gl_Position = gl_ModelViewProjectionMatrix * vec4(point.xy, 0.0, 1.0);

gl_FrontColor = gl_Color;
gl_BackColor = gl_Color;
}

I’ve successfully loaded, compiled, added to the shader to a program, and linked the program.

Now that I have the shader program its not clear how to use the program such that is affects the way my vertex arrays are drawn. I’ve tried the following but it appears to have no effect as it draws things exactly like there were without the shader:

glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(4, GL_INT, 4*sizeof(GLint), &data1[0][0]);

//New shader code here
glUseProgram(shaderProg);
int plotAxes = rand()%4;
GLint axes = glGetUniformLocation(shaderProg, "axes"); 
glUniform1i(axes, plotAxes);

glDrawArrays(GL_POINTS, 0, MAX_N_POINT-1);
glDisableClientState(GL_VERTEX_ARRAY);  
glUseProgram(0);

Is there something fundamental that I am missing or don’t understand properly?

Edit 2: I’ve updated the shader code per Christian’s suggestions. I’ve also verified that shade loads without errors however if I check for OpenGl errors after I call glUseProgram I get an OpenGL Error: invalid operation error.

Edit 3: Here is the final shader that worked:

uniform int axes;

void main()
{
  vec4 point; 
  if (axes == 0) {
     point = gl_Vertex; 
  } else if (axes == 1) {
     point = gl_Vertex.xzyw; 
  } else if (axes == 2) {
     point = gl_Vertex.xwzy; 
  } else if (axes == 3) {
      point = gl_Vertex.yzxw; 
  } else if (axes == 4) {
     point = gl_Vertex.ywxz; 
  } else if (axes == 5) {
     point = gl_Vertex.zwxy; 
  }

  point.z = 0.0; 
  point.w = 1.0; 

  // eliminate w point
  gl_Position = gl_ModelViewProjectionMatrix * point;

    gl_FrontColor = gl_Color;
    gl_BackColor = gl_Color;
}
  • 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-26T04:26:36+00:00Added an answer on May 26, 2026 at 4:26 am

    You have to set the axes uniform (glUniform1i) after you enabled/use the program (glUseProgram), otherwise it doesn’t have any effect (and your axes uniform keeps its default value, which seems to be 0). But I hope your program also contains a valid fragment shader that uses your passcolor varying, as the fixed function fragment processor doesn’t know what to do with this varying.

    And by the way, although it won’t cost you that much if all vertices take the same path anyway, but using 6 different shaders would be a better idea performance-wise. You can still use preprocessor macros to reduce the writing overhead.

    EDIT: From your update it seems you don’t use a special fragment shader. So you just use the builtin fragment pipeline together with your vertex shader. Whereas this is possible, you still have to match both stages to work together. Your passcolor varying is completely useless, as the fixed-function pipeline doesn’t know what to do with it. Just use the buitlin color varying and replace

    passcolor = gl_Color;
    

    with

    gl_FrontColor = gl_Color;
    gl_BackColor = gl_Color;       //just to be sure
    

    You should also check if your shaders compile and link successfully and inspect the info log in case they don’t, as I suppose your program won’t link because of the above varying inconstencies. So you end up with not using the shader (and with a bunch of GL_INVALID_OPERATIONs) without noting it.

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

Sidebar

Related Questions

I have a one-dimensional array of strings in JavaScript that I'd like to turn
I have an Nx4 array of vertices that I'd like to plot using glVertexArray
I have an multi-dimensional array that I want to send to a PHP script
I have 3d mesh and I would like to draw each face a 2d
i have multi dimensional array like below, Array ( [14289] => Array ( [0]
I have a n-dimensional Boost.MultiArray I initialize as follows: const int n=3, size=4; //#
I have a two dimensional array like this $FrstArr = Array( [0]= array( [0]=>101,
I have a two dimensional array that I need to rotate 90 degrees clockwise,
I have a 2-dimensional(3x7) array. I would like to sort it per row. I
I have a bi-dimensional np.array like x = np.array([[1,2], [4,5], [4,6], [5,4], [4,5]]) now

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.