Using multiple files in Marmalade SDK - c++

The title is pretty self explanitory: I'm trying to run a process outside of main.cpp using loadfile.cpp and loadfile.h to handle loading and displaying an image. However, Marmalade keeps throwing build errors when I do this.
At a top level, I am looking for a process that will run in main.cpp, make a call to loadfile.cpp and display an image with the code in loadfile.cpp. Ideally:
in main.cpp:
main()
{
//initialize and setup Marmalade stuff
Img* myImg; //create an image object
while (!s3eDeviceCheckQuitRequest()) {
//More Marmalade stuff
myImg->display(); //display said image
}
delete myImg;
return 0;
}
in loadfile.cpp:
#include "loadfile.h"
Img* myImg; //image object
void Img::displayImg()
//display image
and in loadfile.h:
#if !defined(_LOADFILE_H)
#define _LOADFILE_H
class File
{
public:
void displayFile();
};
extern Img* myImg;
#endif //_LOADFILE_H
Can someone point out what I am doing wrong or write a brief script showing me it? Thanks very much!
P.S. I wrote this following the Stage 2 Marmalade looking at what they do with the input.cpp/.h files and Input class. I have the full code available if that would be of help!

You need to mention all of your source files in the mkb, before you can use them in your project. Look for the mkb's source section to add the files. Once done, reload the mkb to find the newly added file in your project automatically.

Related

Open a Window in JUCE and put a PluginEditor into it

The tl;dr How do I open a window in Juce to display a plugin Editor?
I am following the Juce AudioProcessGraph tutorial at https://docs.juce.com/master/tutorial_audio_processor_graph.html which shows how to dynamically load AudioProcessor objects.
I would like to open their GUIs as they're loaded. This could be in separate windows or in the window that's got the slots for the graph.
I've tried creating a AudioProcessorEditor, but I'm at a loss on how to tell it to open.
Edit to add: What I've tried so far:
I've downloaded the code from the Tutorial: Cascading plug-in effects from https://docs.juce.com/master/tutorial_audio_processor_graph.html
I've also used ProJucer to create a new plugin. I've put the new plugin's files into the tutorial's files and used ProJucer to add PluginEditor.cpp and PluginEditor.h to the tutorial project.
I've changed the PluginEditor.h so the private class member audioProcessor is of type ProcessorBase&. And made ProcessorBase& the expected type for the data passed to the constructor.
In the tutorial code, in the header file, I've changed the ProcessorBase class so that the methods hasEditor() and createEditor() are just declarations and then modified main.cpp as follows:
#include "PluginEditor.h"
#include <iostream>
//=======================================================
juce::AudioProcessorEditor* ProcessorBase::createEditor()
{
std::cout "asking for an editor\n";
return new NewProjectAudioProcessorEditor (*this);
}
bool ProcessorBase::hasEditor() const
{ return true; }
In the included header, in the TutorialProcessor class, in the updateGraph() method, under the if (hasChanged), I've added slot->getProcessor()->createEditorIfNeeded (); on line 387-ish.
I can tell from my cout that createEditor() is being called and know that the constructor for the editor is running, but no window opens.
How do I tell it to open a window?
The code compiles and runs, but no window opens.

Sample application with imgui library generate error

I am new in imgui and just installed it with vcpkg and created an application in vs2022 and add these codes:
#include <imgui.h>
using namespace std;
void MySaveFunction()
{
}
int main()
{
ImGui::Text("Hello, world %d", 123);
if (ImGui::Button("Save"))
MySaveFunction();
}
but when I run this application I get this error:
What minimum code do I need to display a window with a button on it?
I searched on the IMGUI website but could not find any simple sample that works.
Dear ImGui provided some detailed examples on how to get started.
Don't be scared to read the code, which might be long and overwhelming if you are new to it.
You basically need to choose a backend, I personally prefer DirectX 11. Then you have to create a window and initialize DirectX. Then create the ImGuiContext - which throws the error for g is nullptr because the context wasn't created, and initialize the backend after that.

Cocos2d-x tilmap black screen

I am a beginner with cocos2d-x and try to use it with Tiled to create maps.
I created a TileMap, and here is my code, in LevelOne::init() in level_one.cpp :
if (!CCLayer::init())
{
return false;
}
_tileMap = new CCTMXTiledMap();
_tileMap->initWithTMXFile("levelone.tmx");
this->addChild(_tileMap);
return true;
The debugger allows me to see that the variable _tileMap contains well (at least a part) of the information in my levelone.tmx file.
But when i run it, got a black screen.
Here is the project on github : https://github.com/LeopoldBriand-bot/Platformer
what would I have misunderstood?
Thanks.
I figure it out: Tiles folder should be on th same disk than .tmx file to have relative path and both should be in Ressource folder.

wxWidgets include image during compile time

I've been trying to make a simple wxWidgets program with just a button with a picture on it. I've been able to make the button with the image on it easily enough, but my problem arises when including it.
So far, I've only been able to fetch the image during run-time (the image has to be in the same folder as the .exe file; otherwise, I get error 2: the system cannot find the file specified). With this method, I have no problems -- the program works just fine. What I'm trying to do, however, is to #include the file so that it is embedded during compile-time, so that it doesn't need to be available during run-time.
I've tried #including the file (both as .png and as .xpm), and I've also tried adding it to the resource includes (this is on Visual Studio 2017). Neither of these worked -- the first method still required the image to be in the same folder, and the second failed during compilation (as far as I can tell, it wasn't able to read the .xpm file).
Here is the relevant code, if it helps:
/*relevant includes*/
#include "happyFace.png" //this isn't working. the file is still needed
||
#include "happyFace.xpm" //ditto
/*I have also tried putting these lines in the resource includes.*/
/*code*/
wxInitAllImageHandlers();
wxBitmap bitmap("happyFace.xpm", wxBITMAP_TYPE_XPM); //only works in same directory at run-time
||
wxBitmap bitmap("happyFace.png", wxBITMAP_TYPE_PNG); //ditto
wxButton *button = new wxButton(this, ID_BMP_BUTTON);
button->SetBitmap(bitmap);
//the rest of the button programming and stuff
Sorry if I haven't provided enough information; I can provide more if necessary. I would really appreciate any help. Thanks!
Two possibilities... Number 1 is simplest. It's been a long time since I wrote the code I'm looking at, so the details are fuzzy.
In Visual Studio, Solution Explorer, add the image into the resource files. Assume the name of the resourse is sample.rc. Then it can be used like so to set the main icon...
SetIcon(wxICON(sample));
Method 1 must be used in order for MS Windows Explorer to display the main icon. I do not remember how to use .rc resources for other things, but it should be easy to figure out.
I did it this way before I discovered VS resource (.rc) files. Compile the file-image into the program "by hand." In other words, write a program that will read an image file and produce bit-for-bit copy in a .cpp file. Then compile that .cpp into the program. Here I have the file-image in memory as an object named dj::main_cursor. Note that the in-memory version is a bit-for-bit copy of a .cur file.
dj::captured_file &c1file(dj::main_cursor);
wxMemoryInputStream cistr(c1file.contents, c1file.size);
cursor1 = wxCursor(wxImage(cistr, wxBITMAP_TYPE_CUR));
FYI, I defined the structure dj::captured_file like so:
struct captured_file {
const char *name;
const unsigned long size;
const void *contents;
captured_file(const char*fn, size_t sz, const void*c)
: name(fn)
, contents(c)
, size(sz)
{}
};
See also, Embedding PNG Images into Windows RC Files
I found some other documentation.
Resources and Application Icon All applications using wxMSW should
have a Windows resource file (.rc extension) and this file should
include include/wx/msw/wx.rc file which defines resources used by
wxWidgets itself.
Among other things, wx.rc defines some standard icons, all of which
have names starting with the "wx" prefix. This normally ensures that
any icons defined in the application's own resource file come before
them in alphabetical order which is important because Explorer
(Windows shell) selects the first icon in alphabetical order to use as
the application icon which is displayed when viewing its file in the
file manager. So if all the icons defined in your application start
with "x", "y" or "z", they won't be used by Explorer. To avoid this,
ensure that the icon which is meant to be used as the main application
icon has a name preceding "wxICON" in alphabetical order.
http://docs.wxwidgets.org/3.1.0/page_port.html
Here is how you should do it:
#include "happyFace.xpm"
wxBitmap bitmap = wxBitmap( happyFace ); // assuming the variable name is "happyFace" inside the xpm
Then you will use bitmap object just like usual. Assuming that the file happyFace.xpm is available for compilation.

Visual Studio not building correctly

I've been having two different problems when trying to compile a C++ project today.
Sometimes it won't reflect any of my changes in the new build: If I change some wording on the output or change around actual functionality and compile and hit Start Debugging, it will behave exactly as it did before I made the changes. Hitting Clean or Rebuild Solution fixes this, but it takes about a full minute to compile this. I guess it's not detecting any changes, but in the output window I see it list the file names of files I made changes to...
I'm also getting a lot of "...already defined in main.obj" errors (one for every function and variable) whenever I try to use a header file or define a function outside of a class. Renaming the functions lets it compile once, but then the second compile will bring up the errors again. It kinda works if I just define the class in a .cpp file, don't use a header file, and don't use any functions outside of the class.
The project is an open-source program I downloaded the other day to mess with (I'm building a bot to control it). I didn't have the first problem until today, but the second one's always been happening. All I've done is add a file (two if you count both Bot.cpp and Bot.h); Bot.cpp includes Bot.h and some files from the program, and the program's main.cpp includes Bot.cpp.
I'll post some code I guess, but I can't find anything wrong with what I'm doing. I'm wondering if there's something I need to do to the existing files? (there were VS solution files included with the project that I used to open it, since VS Express doesn't help you create projects from existing code.)
//Bot.h
#ifndef _Bot_h_
#define _Bot_h_ 1
#include <string>
class Bot{
private:
uint32 inputs = 0;
bool active = false;
public:
Bot(){};
~Bot(){};
void Start();
void Stop();
void Run();
void Wait(int seconds);
void Press(int buttons);
};
#endif
//Bot.cpp
#ifndef _Bot_cpp_
#define _Bot_cpp_ 1
#include "main.h"
//Some other project files included between these
#include "Bot.h"
using namespace std;
void Bot::Start(){
if (active == false){
active = true;
Run();
}
}
void Bot::Stop(){
active = false;
}
void Bot::Run(){
while (active == true){
printf("Has my code updated?\n");
Wait(2);
}
}
//There are more functions defined here
#endif
All I've really done in the original source code is include Bot.cpp at the bottom of the list of includes in the main.cpp file, and then add a call to create the class. I'm a little out of practice with C/C++ so maybe it's something simple. I'm also bad at writing posts like this so if anything needs clarified I'll try to help.