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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:18:53+00:00 2026-05-31T10:18:53+00:00

Code below is working fine and draw a colored triangle equal sides: GLfloat triangle_pos[]

  • 0

Code below is working fine and draw a colored triangle equal sides:

GLfloat triangle_pos[] =
                 {
            -0.5, -0.25, 0.0,
             0.5, -0.25, 0.0,
             0.0, 0.559016994, 0.0
                 };

void draw_triangle()
{
 glUseProgram(SHADER.program);

 matrix mv;
 multiply_matrix(VIEW_MATRIX/*ident*/, MODEL_MATRIX/*ident*/, mv);
 matrix mvp;
 multiply_matrix(PROJECTION_MATRIX/*ortho*/, mv, mvp);

 glUniformMatrix4fv(SHADER.uniforms[0]/*um_mvp*/, 1, GL_FALSE, mvp);

 glEnableVertexAttribArray(SHADER.atributes[0]/*av_pos*/);
 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, triangle_pos);

 glDrawArrays(GL_TRIANGLES, 0, 3);

 glDisableVertexAttribArray(SHADER.atributes[0]/*av_pos*/);

 glUseProgram(0);
}

Vertex shader:

attribute vec4 av_pos;
varying vec4 vv_col;
uniform mat4 um_mvp;
void main()
{
 vv_col = um_mvp * av_pos;
 gl_Position = vv_col; 
} 

Fragment shader:

precision lowp float;
varying vec4 vv_col;
void main()
{
 gl_FragColor = vv_col;
}   

Lets change vertex shader to load color values from outside:

attribute vec4 av_pos;
attribute vec4 av_col;
varying vec4 vv_col;
uniform mat4 um_mvp;
void main()
{
 vv_col = av_col
 gl_Position = um_mvp * av_pos; 
}  

And modified code will be:

GLfloat triangle_pos[] =
                 {
            -0.5, -0.25, 0.0,
             0.5, -0.25, 0.0,
             0.0, 0.559016994, 0.0
                 };

GLfloat triangle_col[]=
                 {
    1.0,0.0,1.0,1.0,
    0.0,1.0,1.0,1.0,
    1.0,0.0,0.0,1.0
                 };



void draw_triangle()
{
 glUseProgram(SHADER.program);

 matrix mv;
 multiply_matrix(VIEW_MATRIX, MODEL_MATRIX, mv);
 matrix mvp;
 multiply_matrix(PROJECTION_MATRIX, mv, mvp);

 glUniformMatrix4fv(SHADER.uniforms[0]/*um_mvp*/, 1, GL_FALSE, mvp);

 glEnableVertexAttribArray(SHADER.atributes[0]/*av_pos*/);
 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, triangle_pos);

 glEnableVertexAttribArray(SHADER.atributes[1]/*av_col*/);
 glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, triangle_col);

 glDrawArrays(GL_TRIANGLES, 0, 3); // just crashing i can't even glGetError() after that line

 glDisableVertexAttribArray(SHADER.atributes[0]);

 glDisableVertexAttribArray(SHADER.atributes[1]);

 glUseProgram(0);
}

Why glDrawArrays crash and how to fix that?

  • 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-31T10:18:54+00:00Added an answer on May 31, 2026 at 10:18 am
    glEnableVertexAttribArray(SHADER.atributes[0]/*av_pos*/);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, triangle_pos);
    
    glEnableVertexAttribArray(SHADER.atributes[1]/*av_col*/);
    glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, triangle_col);
    

    glVertexAttribPointer‘s first argument is the attribute to set. It’s the same value as what you give to glEnableVertexAttribArray. So this should be:

    glEnableVertexAttribArray(SHADER.atributes[0]/*av_pos*/);
    glVertexAttribPointer(SHADER.atributes[0], 3, GL_FLOAT, GL_FALSE, 0, triangle_pos);
    
    glEnableVertexAttribArray(SHADER.atributes[1]/*av_col*/);
    glVertexAttribPointer(SHADER.atributes[1], 4, GL_FLOAT, GL_FALSE, 0, triangle_col);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My below code is working fine when used in HTML. The same code I
Hopefully a nice and quick one for you... the below code is working fine
I'm having trouble with some MYSQL. The code below has been working fine until
I have this code (below) working just fine, however whenever I try to 'wrap'
I have the below code working fine up to 150 consecutive threads. Anything over
The below code is working fine. But if i change the html string in
My CSS code below is working fine in Chrome, but isn't working in Firefox.
code below working fine but not in IE6, IE7, below is the code is
I got a little problem with ViewBag and DropDownListFor. Code below Working fine but
the below code is working fine if the user enters the USN number that

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.