Post by Nicky Peter Hollyoake on Oct 24, 2008 6:08:08 GMT -5
Ok, this tutorial is a carry on from the first, I won't be explaning stuff in this read my last tutorial to understand them.
First where the include files are put ...
to add the gl library.
Next make your code ...
You should know where this goes if you read my last tutorial.
Next register it ...
RegisterVoidFunction is "Sub" in Basic4GL, see how I don't need to put a return type at the end (eg: DLL_BASIC4GL_INT, etc). We don't need "registry.AddParam" becauses theres no parameters we'll just be having it like "Point()".
if you get these errors when building ...
Go to 'Project > build options > linker settings tab'
under where it says "Link Libraries" press on "add" and type "opengl32" press ok, then ok again to set it in, and then press on build again.
Hope this helps people!
- Nicky
EDIT:
The function we just made is used in Basic4GL like this ...
Its just to make points.
Full source
First where the include files are put ...
#include <GL/gl.h>
to add the gl library.
Next make your code ...
void DLLFUNC Func_Point(IDLL_Basic4GL_Runtime &basic4gl) {
glBegin (GL_POINTS);
glVertex2f(0, 0);
glEnd();
}
You should know where this goes if you read my last tutorial.

Next register it ...
registry.RegisterVoidFunction ("Point", Func_Point);
RegisterVoidFunction is "Sub" in Basic4GL, see how I don't need to put a return type at the end (eg: DLL_BASIC4GL_INT, etc). We don't need "registry.AddParam" becauses theres no parameters we'll just be having it like "Point()".
if you get these errors when building ...
||=== PluginDLL, Release ===|
Release\PluginDLLMain.o:PluginDLLMain.cpp:(.text+0x6e)||undefined reference to `_glBegin@4'|
Release\PluginDLLMain.o:PluginDLLMain.cpp:(.text+0x83)||undefined reference to `_glVertex2i@8'|
Release\PluginDLLMain.o:PluginDLLMain.cpp:(.text+0x8c)||undefined reference to `_glEnd@0'|
||=== Build finished: 3 errors, 0 warnings ===|
Go to 'Project > build options > linker settings tab'
under where it says "Link Libraries" press on "add" and type "opengl32" press ok, then ok again to set it in, and then press on build again.
Hope this helps people!
- Nicky
EDIT:
The function we just made is used in Basic4GL like this ...
GLTransLateF(0, 0, - 10)
Point()
Its just to make points.
Full source
/* Example DLL project.
Created by: Thomas Mulgrew (tmulgrew@slingshot.co.nz)
This project will build a simple DLL that can be plugged into Basic4GL.
It contains one library function for example purposes.
I recommend using this as a template for creating Basic4GL plugin DLLs.
*/
///////////////////////////////////////////////////////////////////////////////
// Includes
// At the very least, Basic4GLDLLInterface.h must be included.
// Add any other include files here.
#include "Basic4GLDLLInterface.h"
#include <GL/gl.h>
///////////////////////////////////////////////////////////////////////////////
// Constants
//
// Update these to describe your DLL.
const char *DESCRIPTION = "[Enter description of DLL here]"; // This is displayed in the "Plug-in Chooser" in Basic4GL
const int VERSION_MAJOR = 1; // Major version number
const int VERSION_MINOR = 0; // Minor version number
///////////////////////////////////////////////////////////////////////////////
// Plugin
//
/// Main object representing the plugin to Basic4GL.
/// Basic4GL will access this through the IDLL_Plugin interface.
class Plugin : public IDLL_Basic4GL_Plugin {
public:
Plugin() { ; }
virtual bool DLLFUNC Load(IDLL_Basic4GL_FunctionRegistry ®istry, bool isStandaloneExe);
virtual bool DLLFUNC Start();
virtual void DLLFUNC End();
virtual void DLLFUNC Unload();
virtual void DLLFUNC GetError(char *error);
virtual void DLLFUNC Pause();
virtual void DLLFUNC Resume();
virtual void DLLFUNC DelayedResume();
virtual void DLLFUNC ProcessMessages();
};
///////////////////////////////////////////////////////////////////////////////
// DLL exported functions
extern "C" {
/// Query function
DLLExport int DLLFUNC Basic4GL_Query(char *details, int *major, int *minor) {
int i;
for (i = 0; DESCRIPTION[i] != 0; i++)
details[i] = DESCRIPTION[i];
*major = VERSION_MAJOR;
*minor = VERSION_MINOR;
return BASIC4GL_DLL_VERSION;
}
/// Main initialisation function.
/// Here we will construct and return our plugin object
DLLExport IDLL_Basic4GL_Plugin *DLLFUNC Basic4GL_Init() {
// Construct and return our plugin object
return new Plugin();
}
}
///////////////////////////////////////////////////////////////////////////////
// Runtime functions
// These are the functions that Basic4GL calls
/// Start ///
void DLLFUNC Func_Point(IDLL_Basic4GL_Runtime &basic4gl) {
glBegin (GL_POINTS);
glVertex2f(0, 0);
glEnd();
}
///////////////////////////////////////////////////////////////////////////////
// Plugin
bool DLLFUNC Plugin::Load(IDLL_Basic4GL_FunctionRegistry ®istry, bool isStandaloneExe) {
// Initialise DLL stuff
// Register shared interfaces
// Register runtime functions
registry.RegisterVoidFunction ("Point", Func_Point);
return true;
}
void DLLFUNC Plugin::Unload() {
// DLL is about to unload.
// Any final cleanup code (closing files, releasing resources etc) would go here
// Delete this object. This is safe because Basic4GL will not access it again.
delete this;
}
bool DLLFUNC Plugin::Start() {
// Program is about to start.
// Any pre-start init code would go here.
return true;
}
void DLLFUNC Plugin::End() {
// Program is about to end
// Any cleanup code would go here
}
void DLLFUNC Plugin::Pause() {
// Called when the program is paused (i.e. during debugging).
// A full screen window might hide itself here so that the user can see the
// Basic4GL edit window (and debug their program)
}
void DLLFUNC Plugin::Resume() {
// Called when the program is resumed (i.e. during debugging).
// This is also called when the user "steps"
}
void DLLFUNC Plugin::DelayedResume() {
// Called when the program is resumed for more than a short "step".
// This is where a fullscreen window would re-show itself (if it did so in ::Resume()
// we would get flickering when the user steps through the program)
}
void DLLFUNC Plugin::GetError(char *error) {
// We don't return errors, but if we did, we would strcpy them to *error here.
;
}
void DLLFUNC Plugin::ProcessMessages() {
// Called periodically (in practice, quite frequently).
// This would be a good place to process windows messages etc.
}