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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:29:18+00:00 2026-05-28T08:29:18+00:00

I have this very simple (yet big) code that doesn’t work. The triangle doesn’t

  • 0

I have this very simple (yet big) code that doesn’t work. The triangle doesn’t show.
It just pass 3 vertexes already multiplied by a ortho-matrix. Do nothing in vertex shader, and paint white in fragment shader.

<head>
    <script type="text/javascript">
        var gl;
        _main_web = function() {
            gl = document.getElementById("canvas").getContext("experimental-webgl");
            gl.clearColor(1,0,0,1);
            gl.enable(gl.DEPTH_TEST);
            gl.viewport(0, 0, 640, 480);
            gl.clearDepth(1);

            buffer = gl.createBuffer();
            gl.bindBuffer(gl.ARRAY_BUFFER,buffer);
            gl.bufferData(gl.ARRAY_BUFFER,
new Float32Array([[-1, -1, -0.12000000476837158, 1, 
0, 1, -0.12000000476837158, 1, 
1, -1, -0.12000000476837158, 1]]),
            gl.STATIC_DRAW);

            vert_shader = gl.createShader(gl.VERTEX_SHADER);
            gl.shaderSource(vert_shader,"attribute vec4 vertex;void main(void) {gl_Position = vertex;}\n");
            gl.compileShader(vert_shader);
            if( !gl.getShaderParameter(vert_shader,gl.COMPILE_STATUS ) ) {
                throw 0;
            }

            frag_shader = gl.createShader(gl.FRAGMENT_SHADER);
            gl.shaderSource(frag_shader,"void main(void) { gl_FragColor = vec4(1.0,1.0,1.0,1.0); } \n");
            gl.compileShader(frag_shader);
            if( !gl.getShaderParameter(frag_shader,gl.COMPILE_STATUS) ) {
                throw 1;
            }

            program = gl.createProgram();
            gl.attachShader(program,vert_shader);
            gl.attachShader(program,frag_shader);
            gl.linkProgram(program);
            if( !gl.getProgramParameter(program,gl.LINK_STATUS) ) {
                throw 2;
            }

            vertexLocation = gl.getAttribLocation(program,"vertex");

            gl.deleteShader(frag_shader);
            gl.deleteShader(vert_shader);
            gl.clear( gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT );

            gl.useProgram(program);
            gl.bindBuffer(gl.ARRAY_BUFFER,buffer);
            gl.enableVertexAttribArray(vertexLocation);
            gl.vertexAttribPointer(vertexLocation,4,gl.FLOAT,false,0,0);

            gl.drawArrays(gl.TRIANGLES,0,3);
        }
    </script>
    <style>
        body {
            margin:0px;
        }
    </style>
</head>
<body onload="_main_web()">
    <canvas id="canvas" width=640 height=480>

    </canvas>
</body>

I am debugging the whole afternoon and couldn’t find the error. getError always return 0. Is there anything I am missing?

  • 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-28T08:29:19+00:00Added an answer on May 28, 2026 at 8:29 am
    gl.drawArrays(4,3,0);
    

    This looks weird. Should look like:

    gl.drawArrays(
        /* mode */ gl.TRIANGLES,
        /* first vertex */ 0,
        /* num vertices */ 3
    );
    

    Also (unimportant):

    gl.useProgram(program);
    gl.bindBuffer(gl.ARRAY_BUFFER,buffer);
    

    The last bindBuffer isn’t important at this moment. You need it when you set an attribute location with gl.vertexAttribPointer, but once it’s set you can change the ARRAY_BUFFER binding to anything.

    You would need to do this if several attributes were located in different VBOs.

    (Note: This is not the case for ELEMENT_ARRAY_BUFFER bindings, which must be set if you do drawElements or something.)

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

Sidebar

Related Questions

I have this very simple example that I am using to learn structs in
Let's say I have a very simple PrototypeJS class that looks like this: var
I have a problem that I'm sure is very simple, yet I have spent
I have this strange, yet maybe very simple problem.. I have a timer1 in
I have this very simple sql statement: SELECT max_dose FROM psychotropes WHERE (patient_meds.psychotrope =
I have this very simple C++ class: class Tree { public: Node *head; };
Have a look at this very simple example WPF program: <Window x:Class=WpfApplication1.Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
I have this html page which is very simple, it contains a text box
Take a very simple case as an example, say I have this URL: http://www.example.com/65167.html
I have very simple select like this: SELECT * FROM table WHERE column1 IN

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.