initialize from another function

M

mikethebike

Hi
if I have this below in int main(int argc, char **argv) it works but
when I move it in another function within the same file.cpp it doesn't
work anymore correctly.
But it has to because I'm doing a shared lib with no main().
WHY errors? What do I have to do differently?
Many thanks
Michael
-------
// If we can initialize the demo
if(demo->init())
{
// Then we run it
demo->run();
}
else
{
// Throw error message
std::cout << "Initialization failed!" << std::endl;
delete demo;
}
 
R

Ron

Hi
if I have this below in int main(int argc, char **argv) it works but
when I move it in another function within the same file.cpp it doesn't
work anymore correctly.
But it has to because I'm doing a shared lib with no main().
WHY errors? What do I have to do differently?

It's impossible to tell with the fragment posted below. Further
when you think things aren't working properly, it's best to say
what you were expecting and what you observed. Most of the time
the group isn't clairvoyant enough to guess from "it doesn't work."

As far as shared libraries without main() functions go, that's
entirely
outside the context of this group. I suspect something is not being
initialzed properly. You don't even show what "demo" is or how it
is initialized.

Besides any class that takes a "init()" function and then a "run()"
function
in addition to being created, is probably a lousy design.
 
J

Jonathan Lee

WHY errors? What do I have to do differently?

It's basically impossible to tell without knowing what the body of init
() is, or how the shared library was loaded. Perhaps init() relies on
global variables being initialized that aren't? demo itself might not
exist depending on how you loaded the library.

All in all, this doesn't sound like a C++ question as much as a
platform question. You might be better off asking the question in a
Linux or Windows newsgroup. Post how you loaded the shared library,
and what you can about init()'s internals.

--Jonathan
 
M

Michael Sgier

Hi
Yes I should have shown the init as there's exectly where I get the
errors. So texLogo = loadTexture("Images/carmine_64x16.png",1,0);
and ftglCreatePixmapFont("Fonts/MgOpenModataOblique.ttf");
don't load or create. Why? That's exactly my problem here.

This shared lib gets loaded from X-Plane as a plugin. Now this was
a openGL standalone app and works if I simply put the previous class
into main. Now I want to call it from within a plugin function and get
rid of window creation and related functions. But first simply get
loadTexture and ftglCreatePixmapFont working. I've included the headers
and it compiles.
As I've only done some VB.NET so far I guess I've the declarations of
loadTexture and ftglCreatePixmapFont at some wrong location? Those
declarations are in another file...can I leave it that way?
Yes this C++ linking is still weird to me...
Many thanks
Michael


* \brief Constructor.
*/
Demo::Demo()
{
m_pCurrCamera = NULL;
m_nCameraIndex = -1;
m_bLighting = FALSE;
m_pfontBig = NULL;
m_pfontMedium = NULL;
texLogo = 0;
}


* \brief Initialises the demonstration.
* \return true, if initialization succeeds.
* false, otherwise.
*/
bool Demo::init()
{
if (!App::init(WIDTH, HEIGHT, BITDEPTH, false, "What is a demo for ?
Showing Off !"))
{
return false;
}

//glDisable(GL_MULTISAMPLE_ARB);
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
//glClearColor(0.827f,0.827f, 0.827f, 0.0f);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

texLogo = loadTexture("Images/carmine_64x16.png",1,0);

m_pfontBig = ftglCreatePixmapFont("Fonts/MgOpenModataOblique.ttf");
if(!m_pfontBig)
{
cout << "Could not load big font"<< endl;
return false;
}
ftglSetFontFaceSize(m_pfontBig, 25, 25);

m_pfontMedium = ftglCreateTextureFont("Fonts/AndikaDesRevG.ttf");
if(!m_pfontMedium)
{
cout << "Could not load medium font"<< endl;
return false;
}
ftglSetFontFaceSize(m_pfontMedium, 14, 14);

m_oDefaultCamera.m_pName = "Default";
m_oDefaultCamera.fLocX = 0;
m_oDefaultCamera.fLocY = -16.0;
m_oDefaultCamera.fLocZ = 16.0;
m_oDefaultCamera.fRotX = 45.0;//90.0;
m_oDefaultCamera.fRotY = 0.0;//180.0;
m_oDefaultCamera.fRotZ = 0.0;
m_oDefaultCamera.fScaleX = 1.0;
m_oDefaultCamera.fScaleY = 1.0;
m_oDefaultCamera.fScaleZ = 1.0;
m_oDefaultCamera.fClipStart = 0.1;
m_oDefaultCamera.fClipEnd = 100.0;
m_oDefaultCamera.fLens = 34.0;
m_oDefaultCamera.m_parrParentIndices = NULL;

resetCameraToDefault();

create3DScene();

m_RotationAngle = 0.0;

return true;
}
 
B

Bart van Ingen Schenau

Michael said:
Hi
Yes I should have shown the init as there's exectly where I get the
errors. So texLogo = loadTexture("Images/carmine_64x16.png",1,0);
and ftglCreatePixmapFont("Fonts/MgOpenModataOblique.ttf");
don't load or create. Why? That's exactly my problem here.

This shared lib gets loaded from X-Plane as a plugin. Now this was
a openGL standalone app and works if I simply put the previous class
into main. Now I want to call it from within a plugin function and get
rid of window creation and related functions. But first simply get
loadTexture and ftglCreatePixmapFont working. I've included the
headers and it compiles.
As I've only done some VB.NET so far I guess I've the declarations of
loadTexture and ftglCreatePixmapFont at some wrong location? Those
declarations are in another file...can I leave it that way?
Yes this C++ linking is still weird to me...
Many thanks
Michael
* \brief Initialises the demonstration.
* \return true, if initialization succeeds.
* false, otherwise.
*/
bool Demo::init()
{
if (!App::init(WIDTH, HEIGHT, BITDEPTH, false, "What is a demo for ?
Showing Off !"))

My first guess would be that App::init returns false, with as result
that the functions in question are never called.
Possible reasons for App:init returning false are:
- The function may not be called by a plugin, but only by an application
- The function was already called once, and fails on every subsequent
invocation
{
return false;
}
<snip - rest of init function>

Bart v Ingen Schenau
 
J

Jonathan Lee

Hi
Yes I should have shown the init as there's exectly where I get the
errors. So texLogo = loadTexture("Images/carmine_64x16.png",1,0);
and ftglCreatePixmapFont("Fonts/MgOpenModataOblique.ttf");
don't load or create. Why? That's exactly my problem here.

I just have a minute, but the first thing that springs to mind is:
Does your working directory change when you are executing from within
the plugin? I'm not sure if a shared library gets its own working
directory, but your description of the symptoms suggests it. Try using
an absolute path. If that works, fix the relative path. Or do
something so the path isn't hard-coded.

--Jonathan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top