Using Sqlite but how to draw information from the database
Posted: Fri Nov 23, 2007 1:26 am
ok, did alot of research and found this, was able to get sqllite connected and it all running in irrlicht. So hopefully this link will help someone else get sqlite running.
on to the question, how do i transfer the information from the database to a variable. I am able to display the information via console but would like to be able to pull information from the database and use it to create and place nodes as well as store information from within irrlicht.
http://www.yeohhs.com/articles/devcppsqlite.htm
[/url]
on to the question, how do i transfer the information from the database to a variable. I am able to display the information via console but would like to be able to pull information from the database and use it to create and place nodes as well as store information from within irrlicht.
http://www.yeohhs.com/articles/devcppsqlite.htm
Code: Select all
#include <irrlicht.h>
//for sqlite
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <sqlite.h>
using namespace irr;
//for sqlite
using namespace std;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
#pragma comment(lib, "Irrlicht.lib")
// used for sqllite
static int callback(void *NotUsed, int argc, char **argv, char **azColName){
int i;
for(i=0; i<argc; i++){
printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
}
printf("\n");
return 0;
}
// end used for sqllite
int main(int argc, char **argv)
{
IrrlichtDevice *device =
createDevice(EDT_DIRECT3D9, dimension2d<s32>(800, 600), 16,
false, true, false, 0);
device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();
// adds the first person shooter camera to the game
// and make the cursor invisible
ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS(0, 100.0f, 100.0f);
device->getCursorControl()->setVisible(false);
ISceneNode* moon = smgr->addSphereSceneNode();
moon->setScale(vector3df(5,5,5));
moon->setPosition(vector3df(200,200,200));
moon->setMaterialFlag(EMF_LIGHTING, false);
moon->setMaterialTexture( 0, driver->getTexture("media/earth.bmp") );
moon->getMaterial(0).EmissiveColor.set(1,1,0,0);
scene::ISceneNodeAnimator* anim =
smgr->createRotationAnimator(core::vector3df(0,0.01f,0));
moon->addAnimator(anim);
anim->drop();
sqlite *db;
char *zErrMsg = 0;
int rc;
char sql[1024]="";
sprintf(sql, "SELECT * FROM table1;");
db = sqlite_open("sqlitepp.db", 0, &zErrMsg);
if (db == NULL )
{
fprintf(stderr, "Can't open database: %s\n", zErrMsg);
sqlite_close(db);
system("PAUSE");
exit(1);
}
rc = sqlite_exec(db, sql, callback, 0, &zErrMsg);
if ( rc!=SQLITE_OK )
{
fprintf(stderr, "SQL error: %s\n", zErrMsg);
}
sqlite_close(db);
smgr->addSkyDomeSceneNode(driver->getTexture("media/sky.jpg"),16,16,1.0f,2.0f);
while(device->run())
{
driver->beginScene(true, true, SColor(255,100,101,140));
smgr->drawAll();
guienv->drawAll();
driver->endScene();
}
device->drop();
return 0;
}