PDA

View Full Version : Method to create Cubes,Triangles etc.



greedsin
02-01-2015, 10:28 AM
Hello all,

I am new to OpenGl and C++ and have a little Question.
I have ONE main.cpp, where i have everything.(Creating Window,rendering the Scene, create VAO and VBO,create and compile Shaders).
Actually i dont really like this.

What i want is more structure to my Code, so for example i can just call a method drawCube(GLfloat position[]), and a Cube at the specified position will be rendered.

But i dont really understand how i can do this .

What i thought about this, that i can pass this method a few more parameters like drawCube(GLfloat position[],GLfloat color[],GLuint vaoID,GLuint vboID).But i dont know if this is the common way .I mean where do i put the Shader then? it should be unique to each object or not?This confuses me a little since i dont see a way to structure my Code.

Hope someone can help me out with this.

Agent D
02-01-2015, 10:59 AM
This question is in no way OpenGL(R) related. It is to some extent about C++, but mostly about object-oriented programming and software design/architecture.

There is no "common way to have a method for drawing cubes".

A typically found architecture in rendering software is to have some sort of scene graph with scene node instances that refere to mesh objects, containing the
geometry and material objects containing references to shaders and shader parameters.

This representation seperates scene geometry from the instances where it is rendered, and geometry from shaders used to render it, that can vary per instance.

I suggest you should learn more about object-oriented programming and software design.

greedsin
02-01-2015, 11:11 AM
Thank you for your answer.About the object-oriented programming, you may be right.I dont really know what to answer .

I've been programming with Java pretty long and i also know about software design, but my problem was just about the opengl things.Maybe the things i wrote work, iam not sure, thats why i wanted to get an answer about my thoughts ;)

Can be closed.

GClements
02-02-2015, 08:52 AM
What i want is more structure to my Code, so for example i can just call a method drawCube(GLfloat position[]), and a Cube at the specified position will be rendered.
In terms of efficiency, such a structure should be avoided.

There is a significant setup overhead for each draw call, so you want to have few draw calls with each call drawing as much as possible.

The limiting factor is that you can't change the program, uniforms, texture bindings, etc in the middle of a draw call. So you try to organise everything into batches of "similar" data.

In turn, this requires a "big picture" overview of the data being rendered, which tends to conflict with the concepts of abstraction and encapsulation on which object-oriented design is based.

That isn't to say that you can't use object-oriented techniques in some form or another, but you can't apply them blindly; you have to compromise with what's convenient for the GPU.