bcm_host.h and c++


8 posts
by panik » Thu Jun 28, 2012 9:06 pm
I'm having great fun with the hello_pi/hello_* examples in /opt/vc/src/, but I have a (basic) question.

When I change the file extension from hello_world/world.c to world.cpp and compile, everything is fine. When I #include "bcm_host.h" or #include <bcm_host.h> in world.c and compile, everything is fine also. Including bcm_host.h in world.cpp however, gives an error:
Code: Select all
pi@raspberrypi /opt/vc/src/hello_pi/hello_world $ make
g++    -c -o world.o world.cpp
world.cpp:23:22: fatal error: bcm_host.h: No such file or directory
compilation terminated.
make: *** [world.o] Error 1

It's the same with the other examples. I'm trying to refactor the triangle.c code to c++. I'm sure I'm missing something obvious, but it's not obvious to me at the moment. A hint in the right direction would be appreciated.
Last edited by panik on Thu Jun 28, 2012 9:24 pm, edited 1 time in total.
Posts: 222
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands
by garethlewis » Thu Jun 28, 2012 9:20 pm
Are you using g++ to compile the c++ code?
Posts: 6
Joined: Thu Jun 28, 2012 9:18 pm
by panik » Thu Jun 28, 2012 9:25 pm
Ah, yes, thank you. I just edited my post to reflect that.
Posts: 222
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands
by garethlewis » Thu Jun 28, 2012 11:21 pm
When I converted the demos from c to cpp, I changed the makefile.include file to use g++ rather than cc and changed the %.o: %c rule to %.cpp. I think it all worked at that point, though bear in mind that the cpp compiler is a bit stricter than cc - so fixes a plenty ;)
Posts: 6
Joined: Thu Jun 28, 2012 9:18 pm
by panik » Thu Jun 28, 2012 11:34 pm
Doh! Sometimes you just have to take a little break and look with fresh eyes.
The "%.o: %.c" in the Makefile.include needed changing to "%.o: %.cpp" of course. I was blinded by include paths.
g++ reports invalid conversion errors in triangle.cpp now. This is one of the few times I'm actually happy to see those. :D

edit: trying to edit the topic title, and report I have a working triangle.cpp. So far, so good!
Posts: 222
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands
by garethlewis » Thu Jun 28, 2012 11:46 pm
The 'new' errors in triangle.cpp are just straightforward c->c++ issues and shouldn't be too much grief to sort out :D
Posts: 6
Joined: Thu Jun 28, 2012 9:18 pm
by panik » Fri Jun 29, 2012 12:06 am
And another post to report that I TOTALLY missed your post, garethlewis. Thank you very much, and my apologies.

But yes, that was the solution indeed. I'm a sucker for 2D, so I'm having a hello_quad now, to create sprites. I want to set the values of quadx that's currently in "cube_texture_and_coords.h" dynamically, something like this (untested, not completely sure about vertex-order):
Code: Select all
GLbyte quadx[4*2] = {
   -width * pivotX, -height * pivotY,
   -width * pivotX, height - (height * pivotY),
   width - (width * pivotX), -height * pivotY,
   width - (width * pivotX), height - (height * pivotY)
}

gcc doesn't let me do that, but g++ does, I have that working.

Edit: Hah! missed your 23:46 post as well. No, g++ didn't give me much pain. Thanks again!
Posts: 222
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands
by garethlewis » Fri Jun 29, 2012 4:45 pm
If you're feeling lazy, just put the verts in unit cuber render-space and get rid of the existing transform / glViewport code, then bottom-left is (-1,-1) and top-right is (1,1). Also, it's worth turning off culling until you can work out what order the triangles are wound in.

Also, have a look at glDrawElements for indexed rendering as you wont need to create so many vertices ;).
Posts: 6
Joined: Thu Jun 28, 2012 9:18 pm