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

  • Home
  • SEARCH
  • 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 6244713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:22:29+00:00 2026-05-24T12:22:29+00:00

I have a simple OpenGL program and trying to draw an instanced array that

  • 0

I have a simple OpenGL program and trying to draw an instanced array that stored in a vertex shader. I’m using two follow shaders for rendering:

Vertex Shader:

#version 330 core

uniform mat4 MVP;

const int VertexCount = 4;
const vec2 Position[VertexCount] = vec2[](
vec2(-100.0f, -100.0f),
vec2( -100.0f, 100.0f),
vec2( 100.0f, -100.0f),
vec2(100.0f, 100.0f));

void main()
{   
    gl_Position = MVP * vec4(Position[gl_VertexID], 0.0, 1.0);
}

Fragment Shader:

#version 330 core
#define FRAG_COLOR      0

layout(location = FRAG_COLOR, index = 0) out vec4 Color;

void main()
{
    Color = vec4(0, 1, 0, 1); //let it will be green.
}

After I’ve compiled and validated these shader I create a vertex array object and draw it like triangle strips:

glUseProgram(programHandle); //handle is checked and valid.
glBindVertexArray(vao);
glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, 1);

The viewport of drawing is set to the window size like glViewport(0, 0, 800, 600). I pass to MVP a simple orthographic matrix with fallow code:

glUniformMatrix4fv(handle, 1, GL_FALSE, (GLfloat*)&matrix); //handle is checked and valid

where the matrix was initialized:

Matrix::CreateOrthographicOffCenter(-200, 200, -200, 200, 1.0f, -1.0f, &matrix);

...
void Matrix::CreateOrthographicOffCenter(float left, float right, float bottom, float top, float zNearPlane, float zFarPlane, Matrix* matrix)
{
memset(matrix, 0, sizeof(Matrix));
    matrix->M11 = 2.0f / (right - left);
    matrix->M14 = (-right - left) / (right - left);
    matrix->M22 = 2.0f / (top - bottom);
    matrix->M24 = (-top - bottom) / (top - bottom);
    matrix->M33 = 1.0f / (zFarPlane - zNearPlane);
    matrix->M34 = (-zNearPlane) / (zFarPlane - zNearPlane);
    matrix->M44 = 1.0f;
}

The problem is I got no triangle strips on my screen. I tried to draw vertex without MVP matrix (gl_Position = vec4(Position[gl_VertexID], 0.0, 1.0)) but also got nothing. How to detect where the problem is?

  • 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-24T12:22:31+00:00Added an answer on May 24, 2026 at 12:22 pm
    glBindVertexArray(vao);
    glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, 1);
    

    And what exactly is stored in that VAO? I’m guessing your answer will be “nothing.”

    If so, then you have run afoul of several problems. If this is a compatibility context (or GL 2.1 or before), then OpenGL does not allow you to render with a VAO that has nothing in it. That is, you can’t render with all attributes disabled. You will get a GL_INVALID_OPERATION error.

    However, if you are in a core context 3.2 or above, then you can render with a disabled VAO.

    Of course, that’s just what the OpenGL specification says. What NVIDIA’s drivers say is that you can render with a disabled VAO in both core and compatibility. What ATI’s drivers say is that you can’t render with a disabled VAO in both core and compatibility.

    In short, if you want your code to work, bind something. Enable an array and put a buffer object there. It doesn’t matter what is in it, since your shader simply won’t care. But if you want it to work on different implementations, bind something.

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

Sidebar

Related Questions

I am trying to draw some contours that I have stored as vertex arrays:
I have a problem using opengl on android to draw a simple rectangle. This
I have a simple openGL D program that compiles, but I can't get it
I have a simple openGL D program that compiles, but I can't get it
I have a simple openGL ES program which basically sets up two triangles which
I have a simple iPhone application which uses OpenGL ES (v1) to draw a
I have a simple openGL GUI that has uses a bmp as a texture.
Suppose I have 5 GLSL shaders that I successfully loaded in my opengl program.
I have some simple OpenGL ES code in C++ that I've run on a
I am trying to write an OpenGL visualization program for some scientific data using

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.