Nothing but Grey

I am trying to go thru the ‘Practical Shader Development’ book by Halladay. I can open and run the examples included in openFramework, but when I run the builds from what I have typed in (I am following the book). i get clean builds but when I run them, all that I get is a gray rectangle when VS is supposed to draw a triangle.
It seems maybe one command is missing ?

I have include the code snippet that defines the triangle altho the problem could be anything.

Thanks for looking.

strong text//--------------------------------------------------------------
void ofApp::setup(){
ofBackground(120, 120, 120);

ofMesh triangle;
triangle.addVertex(glm::vec3(0.0, 0.0, 0.0));
triangle.addVertex(glm::vec3(0.0, 380.0, 0.0));
triangle.addVertex(glm::vec3(600.0, 380.0, 0.0));


What happens if you try:


before drawing the triangle?

1 Like

moved the construction of the triangle from ‘void setup()’ to ‘void draw()’ and results are as initially expected. The book clearly says that that they go in setup but that approach does not work.

you have a scope problem there.
by declaring

ofMesh triangle;

inside of setup it means that it will only exist inside of setup, thus trying to call access triangle from draw will give you an error. google about “C++ variable scope” and you might get an more detailed explanation.

moving all the code to the draw function will work but you’ll be generating and populating the mesh on each frame, which for simple meshes is not a big problem but it can become really inefficient for larger and more complex meshes.

solution, move the declaration of of the mesh, thus ofMesh triangle; to the ofApp.h file, must go inside the curly brackets that define ofApp. Then just keep the code where you add vertices in the setup and then call triangle.draw() inside ofApp::draw().

1 Like