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 9 of 9

Thread: caching mechanism in OpenGL????

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2019
    Posts
    5

    Exclamation caching mechanism in OpenGL????

    So basically i want to know is there any caching mechanism?like i need to..
    1) Can i first draw a line and then later specify its color?
    2) Can i first draw a shape(using GL_LINE_LOOP) and in next step fill it with a color? (Not to use GL_POLYGON which specify the shape to be filled initially )
    3) Saving the current coordinate ( pen coordinate )
    Basically need to fill the previous shape i made.
    If OpenGL dont have such mechanism what can i do in c++?

  2. #2
    Senior Member OpenGL Lord
    Join Date
    May 2009
    Posts
    6,086
    The answer to all of your questions is "no".

    You are expected to make all of those decisions before you send data to OpenGL. OpenGL is a low-level API, so your code is expected to conform to its requirements, not have OpenGL to conform to yours.

    If you want to be able to program that way, then you will need to build an abstraction on top of OpenGL that doesn't make OpenGL calls until some point later, after you have provided all of the information needed for doing the rendering.

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2019
    Posts
    5

    Post Maybe there is a solution???

    ------------------------------
    From somewhere i get this code , First drawing a rectangle and later changing its color(i dont know how its doing)
    Can someone please explain it????????????????
    --------------------------------

    Code cpp:
    #define GL_GLEXT_PROTOTYPES
    #include <GL/glut.h>
    #include <string.h>
     
    int nbVertices = 4;
    void* colorOffset = (void*) (sizeof( float ) * 12);
    float initialVBO[24] = {0,0,0,  0.5,0,0,  0,0.5,0,  0.5,0.5,0,    1,1,1,  1,1,1,  1,1,1,  1,1,1};
    GLuint vboID;
     
    void displayFunc(void) {
        glClear(GL_COLOR_BUFFER_BIT);
     
        glBindBuffer(GL_ARRAY_BUFFER, vboID);
     
     
        glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_COLOR_ARRAY);
     
        glVertexPointer(3, GL_FLOAT, 0, NULL);
        glColorPointer(3, GL_FLOAT, 0, colorOffset);
     
        glDrawArrays(GL_TRIANGLE_STRIP, 0, nbVertices);
     
        glBindBuffer(GL_ARRAY_BUFFER, 0);
     
        glFlush();
    }
     
    void mouseFunc(int button, int state, int x, int y) {
        float color[12] = {1,0,0,  1,0,0,  1,0,0,  1,0,0};
        glBindBuffer(GL_ARRAY_BUFFER, vboID);
     
        void* vboAddress = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
        if(!vboAddress) {
            return;
        }
        memcpy((char*)vboAddress + sizeof( float ) * 12, color, sizeof( float ) * 12);
     
        glUnmapBuffer(GL_ARRAY_BUFFER);
        vboAddress = NULL;
     
        glBindBuffer(GL_ARRAY_BUFFER, 0);
     
        displayFunc();
    }
     
    int main(int argc, char** argv) {
        glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_SINGLE);
        glutInitWindowSize(300, 300);
        glutInitWindowPosition(0, 0);
        glutCreateWindow("Rectangle fill");
     
     
        glGenBuffers(1, &vboID);
        glBindBuffer(GL_ARRAY_BUFFER, vboID);
     
        glBufferData(GL_ARRAY_BUFFER, sizeof(initialVBO), 0, GL_STATIC_DRAW);
        glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(initialVBO), initialVBO);
     
        glBindBuffer(GL_ARRAY_BUFFER, 0);
     
     
        glutDisplayFunc(displayFunc);
        glutMouseFunc(mouseFunc);
        glutMainLoop();
     
        glDeleteBuffers(1, &vboID);
        return 0;
    }
    Last edited by Dark Photon; 01-10-2019 at 07:43 PM.

  4. #4
    Junior Member Newbie
    Join Date
    Jan 2019
    Posts
    5

    Can i do something with glBufferSubdata?

    [https://www.khronos.org/registry/Ope...rSubData.xhtml

    glBufferSubData, glNamedBufferSubData updates a subset of a buffer object's data store

  5. #5
    Senior Member OpenGL Lord
    Join Date
    May 2009
    Posts
    6,086
    First drawing a rectangle and later changing its color
    No, it first draws a rectangle. Then, when you press the mouse button, it draws a new rectangle using different values from the previous one. It is not changing the color of what it drew; it is merely drawing a new frame with a rectangle that has a different color.

  6. #6
    Junior Member Newbie
    Join Date
    Jan 2019
    Posts
    5
    What basically I need is.. From a different program(some functions) use opengl main function and draw.
    For example
    /______
    ............
    MakeRectangle(x1,y1,x2,y2);
    Selectcolor(r,g,b);
    Stroke(); // here it draws just a wire rectangle of selected colour boundary
    ............
    /______
    ............
    MakeRectangle(x1,y1,x2,y2);
    Selectcolor(r,g,b);
    Fill()
    Stroke(); // here it draws a filled rectangle of selected colour
    ............
    /______
    ............
    Moveto(x,y)
    Makeline(x1,y1);
    Makeline(x2,y2);
    Closeregion();
    Selectcolor(r,g,b);
    Stroke(); // here it draws just a triangle filled with selected colour
    ............
    /_______

    How to connect these func with opengl code (without changing the order of func calls here that is selectcolor or close region after make line or makereactangle)

    (Note: need to render only in stroke)

    Is there any solution using VBO, VAO????????
    Retained mode?? Not immediate mode..
    Help!!!!!!!!

  7. #7
    Senior Member OpenGL Lord
    Join Date
    May 2009
    Posts
    6,086
    Um, isn't this kind of obvious? `Stroke` is the function that tells your system "draw the stuff I told you about". So that's where you put all of the OpenGL calls. Until then, you just hold on to the information they set in your own data structures.

  8. #8
    Junior Member Newbie
    Join Date
    Jan 2019
    Posts
    5

    Different shapes in same Buffer object????

    Can i save whether a shape would be unfilled or filled? whether it will be closed or not?

  9. #9
    Senior Member OpenGL Lord
    Join Date
    May 2009
    Posts
    6,086
    You are a programmer; you can do whatever you want. My overall point is that your solution will, at the end of the day, have nothing to do with OpenGL itself.

    You cannot turn each of those calls into direct OpenGL calls. You have to store their data and submit the appropriate OpenGL calls when `Stroke` gets called. How you store that data is up to you.

Posting Permissions

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