Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: OpenGL VBO and VAO, generating many points and ellipses

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2017
    Posts
    3

    OpenGL VBO and VAO, generating many points and ellipses

    Hello!

    I am the beginner of using Modern OpenGL with shaders. I have a program that have that generates many points on screen like 500x500 or 100x100. That works perfectly with VBO and VAO. Here is the code and a video representation of my program:

    https://media.giphy.com/media/xT9IgG...pJxC/giphy.gif


    Code :
    void Mesh::SetupSeeds()
    {
    	//SEEDS
    	glGenVertexArrays(1, &VAO);
    	glGenBuffers(1, &VBO_SEED);
    	glBindVertexArray(VAO);
    	glBindBuffer(GL_ARRAY_BUFFER, VBO_SEED);
    	glBufferData(GL_ARRAY_BUFFER, seeds.size() * 5 * sizeof(float), vertex, GL_STATIC_DRAW);
     
    	// vertex positions
    	glEnableVertexAttribArray(0);
    	glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 5* sizeof(float), (void*)0);
    	// vertex colors
    	glEnableVertexAttribArray(1);
    	glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 5* sizeof(float), (void*)(2 * sizeof(float)));
     
    	glBindVertexArray(0);
    }

    Code :
    void Mesh::Draw(Shader shader)
    {
    	glUniform1f(seedSizeUniformLocation, seedSize);
    	glBindVertexArray(VAO);
    	glDrawArrays(GL_POINTS, 0, seeds.size());
    }


    And now I need to draw ellipses on that generated "seeds". How may I do that with not removing generated mesh?

  2. #2
    Junior Member Newbie
    Join Date
    Sep 2017
    Posts
    3
    UPDATE:

    Here is the example of effect i would like to have. I dont ask about what alghorithm i need to have, to generate the red ellipses and rects, but i would like to know how i can draw something on that actual screen with that actual mesh.

    Click image for larger version. 

Name:	Untitled.jpg 
Views:	18 
Size:	12.3 KB 
ID:	2482

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,411
    Convert the points to rectangles, either client-side or using a geometry shader.

    You can use a fragment shader to render a rectangle as an ellipse, e.g.:
    Code :
    if (u*u+v*v>1) discard;
    where u and v range from -1 to +1 over the rectangle.

    Point sprites could be used, but there's an implementation-dependent upper limit on the size, and that limit isn't required to be larger than a single pixel.

  4. #4
    Junior Member Newbie
    Join Date
    Sep 2017
    Posts
    3
    Ok, thank you for advise. I will try to work on it

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •