|
C++ and OpenLayer questions |
ngiacomelli
Member #5,114
October 2004
|
I have a few questions concerning C++ and OpenLayer (I'm new to both). I've got a working framework but now I have a few questions: First of all, I want to ask about namespaces. I have a file called: render.cpp, that contains the main OpenLayer rendering code. In this file I declare the use of the ol namespace. In a header file included in render.cpp (render.h) I have a declaration for an OpenLayer TextRenderer (held within header guards). When I try to compile this code, I get an error. By declaring the ol namespace again inside of render.h, this solves the problem. So what's the right thing to do, in this situation? Declare the namespace inside of render.h but outside of the header guards and ditch the namespace declaration inside of render.cpp or is it common to have both? My other question is using OpenLayer along with standard OpenGL calls. I've read a few of the NeHe tutorials and was wondering how I should go about it? My plan was to get OpenLayer working nicely around my standard framework, and then work through NeHe tutorials to learn OpenGL. If someone could supply a clean way of doing this, I'd be very thankful.
|
Indeterminatus
Member #737
November 2000
|
To answer your first question: Unless you are planning on extending OpenLayer, you are well advised not to declare the namespace ol, but rather to use it. TextRenderer as such won't work, then, of course, because it's not in the global namespace, and you are not referencing it from its own namespace. The solution to your problem is to use ol::TextRenderer. Another possible solution would be to put a "using namespace ol;" somewhere, but I do not recommend that one, as it ruins the namespace's original intent. _______________________________ |
ngiacomelli
Member #5,114
October 2004
|
Whoops. I should explain, when I say I 'declared' the namespace, I was doing: 'using namespace ol'.
|
Carrus85
Member #2,633
August 2002
|
It would help if you gave us a snippet of the offending code, but my guess is that you are trying to use openlayer functions in your render.h without prepending the proper namespace identifier (ol::*), hence why it compiles when you tell it to explictily include everything in the openlayer namespace into your current namespace (using namespace ol), but throws craploads of errors when you don't.
|
Indeterminatus
Member #737
November 2000
|
Alright, sorry then for the confusion. Mind to show some code, then? And the error message you were talking about might also be helpful edit: Damn, beaten _______________________________ |
Fladimir da Gorf
Member #1,565
October 2001
|
Quote: My other question is using OpenLayer along with standard OpenGL calls. I've read a few of the NeHe tutorials and was wondering how I should go about it? My plan was to get OpenLayer working nicely around my standard framework, and then work through NeHe tutorials to learn OpenGL. If someone could supply a clean way of doing this, I'd be very thankful. You can use any OpenGL commands along with OL, but beware that a few functions might change the OpenGL state (the active color, for example) OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori) |
ngiacomelli
Member #5,114
October 2004
|
A snippet from graphics.cpp:
From graphics.h:
Code works fine but should I really need to use: using namespace ol twice?! Here's some code from a NeHe tutorial. I was wondering how I'd go about integrating it with my rendering code (also below):
void Application::Render() { Transforms::ResetTransforms(); Transforms::SetColorChannels( Rgba::WHITE ); GfxRend::RefreshScreen(); }
|
Fladimir da Gorf
Member #1,565
October 2001
|
Quote: Here's some code from a NeHe tutorial. I was wondering how I'd go about integrating it with my rendering code (also below):
OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori) |
ngiacomelli
Member #5,114
October 2004
|
How odd, I just get a black screen. No crash, it's just not rendered.
|
|