I am having problem managing my code and imagining a good design. What i wanna do is simply draw a line first, then after line has been rendered, draw the square so it overlaps the line partially and then keep on doing this.
I created 2 classes, Lines
and Squares
. I have set up and bounded a VAO and a VBO in the main class. In my lines and squares classes i only pass the data to this buffer and make appropriate calls to VertexAttribPointer
and GlDrawArrays
in their draw()
method.
In the main class there is a main game loop that runs infinitely till the user closes the window. Now what i want to do is call the draw()
method of both Lines
and Squares
in an Update()
method. After this Render()
is called which only swaps buffers and polls events. Basically a rough sketch is...
while(window_close != true)
{
update();
render();
}
public void update()
{
GL11.glClearColor(0.2f,0.4f,0.3f, 1);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
lines.draw(); // object of Lines class
squares.draw(); // object of Squares class
}
public void render()
{
swapbuffers();
}
But there is a problem since update is in a loop it'll feed lines data into the buffer then it'll overwrite that data with squares one. I want it to alternate i.e render lines, then square. Hence i thought to have a flag inside each class. Before the draw()
methods feed data they would check which one has been rendered and then draw accordingly or else return and do nothing.
Furthermore since at the start of Update()
The background is cleared, i need to draw lines, render it, then draw squares and render it before clearing the background. I know i could do
while(window_close != true)
{
GL11.glClearColor(0.2f,0.4f,0.3f, 1);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
lines.draw();
render();
squares.draw();
}
which is ok, but for bigger projects it'd become ugly. i'd have to write render()
alternatively.