I am planning to use CEGUI for an OpenGL project and I was wondering if there was any way to not use GLUT which is used in the example of the GL renderer (and the only example i have ). Any examples on how to do it without GLUT would be greatly appreciated.
Thanks in advance!
Nikon
OpenGL Renderer without GLUT
Moderators: CEGUI MVP, CEGUI Team
- wingdongdoodle
- Just popping in
- Posts: 15
- Joined: Tue Mar 15, 2005 21:41
Re: OpenGL Renderer without GLUT
ok, its pretty simple to do without GLUT. in fact, its *nearly* exactly the same.
let me say at first, these directions may have some useless steps, as m learning this as well still, but here it goes
first off, you need to link with the openGL renderer (openGLGUIRender.lib i believe)
well, heres some chunks of source code (of what i got working with CEGUI)
includes i use:
setting up the renderer - you really only need the rendering creating code
heres how to draw it to the screen:
put this in your main loop or whatnot
heres how to insert key presses & mouse events
i use SDL, so replace mSDLEvent.keypress with whatever you plan on using to handle keyboard commands, and the injection comands take chars and unicode.
mCurrentTime is just a variable that holds the current time in seconds
mElapsed time holds elapsed time since last update (also global, and in seconds)
and heres the function i use to load a random layout.xml
and heres the destructor...
for creating windows in code, the openGL demo shows some examples of random widget creation. hope some of this helps, its a bit disorgonized... but, its all i really have at the moment. good luck
also, its almost st patricks day, so
let me say at first, these directions may have some useless steps, as m learning this as well still, but here it goes
first off, you need to link with the openGL renderer (openGLGUIRender.lib i believe)
well, heres some chunks of source code (of what i got working with CEGUI)
includes i use:
Code: Select all
//-----------
//Crazy Eddies GUI includes
//------------
#include <CEGUI.h>//main include
#include <CEGUIGUILayout_xmlHandler.h>//XML loading
#include "Renderers/OpenGLGUIRenderer/openglrenderer.h"
#include <sstream> //for use with the FPS stats
//global variable - or variable in a class, etc.
//need it for the renderer
CEGUI::OpenGLRenderer *mCEGUIRenderer;
setting up the renderer - you really only need the rendering creating code
Code: Select all
void MainApplication::setupCEGUI()
{
// Set the clear color
glClearColor (0.0, 0.0, 0.0, 1.0);
// Enable depth testing
glEnable( GL_DEPTH_TEST );
// Draw the back faces of polygons in wireframe
glPolygonMode( GL_FRONT, GL_FILL );
glPolygonMode( GL_BACK, GL_LINE );
mCEGUIRenderer = new CEGUI::OpenGLRenderer(1024);
new CEGUI::System(mCEGUIRenderer);
//used for repeating keys
mLastKeyInjected=0;
mLastKeyInjectTime=0.0;
mKeyInjectRate=0.15;
}
heres how to draw it to the screen:
put this in your main loop or whatnot
Code: Select all
CEGUI::System::getSingleton().renderGUI();
heres how to insert key presses & mouse events
i use SDL, so replace mSDLEvent.keypress with whatever you plan on using to handle keyboard commands, and the injection comands take chars and unicode.
mCurrentTime is just a variable that holds the current time in seconds
mElapsed time holds elapsed time since last update (also global, and in seconds)
Code: Select all
void MainApplication::updateCEGUI()
{
if(mSDLEvent.type==SDL_KEYDOWN)
{
//repeat control
if(mLastKeyInjected!=mSDLEvent.key.keysym.sym||mLastKeyInjectTime+mKeyInjectRate<=mCurrentTime)
{
mLastKeyInjected=mSDLEvent.key.keysym.sym;
mLastKeyInjectTime=mCurrentTime;
if(mSDLEvent.key.keysym.sym==SDLK_BACKSPACE)
{
mCEGUISystem->injectKeyDown(0x0E);
}
else if(mSDLEvent.key.keysym.sym==SDLK_RETURN)
{
mCEGUISystem->injectKeyDown(0x1C);
}
else
{
mCEGUISystem->injectChar( mSDLEvent.key.keysym.unicode );
mCEGUISystem->injectKeyDown( mSDLEvent.key.keysym.unicode );
}
}
}
if(mSDLEvent.type==SDL_KEYUP)
{
//mCEGUISystem->injectKeyUp(mSDLEvent.key.keysym.sym);
mCEGUISystem->injectKeyUp( mSDLEvent.key.keysym.unicode );
}
if(mMouseButtons&SDL_BUTTON(1))
{
mCEGUISystem->injectMouseButtonDown(CEGUI::LeftButton);
}
else
{
mCEGUISystem->injectMouseButtonUp(CEGUI::LeftButton);
}
//mCEGUISystem->injectMouseButtonUp();
//mCEGUISystem->injectMouseMove();
mCEGUISystem->injectMousePosition(mMouseX,mMouseY);
//mCEGUISystem->injectMouseWheelChange();
mCEGUISystem->injectTimePulse(mElapsedTime);
}
and heres the function i use to load a random layout.xml
Code: Select all
void MainApplication::loadCEGUI(std::string filename)
{
using namespace CEGUI;
try{
Logger::getSingleton().setLoggingLevel(Informative);
mCEGUISchemeManager = SchemeManager::getSingletonPtr();
if(!mCEGUISchemeManager->isSchemePresent((utf8*)"TaharezLook"))
mCEGUISchemeManager->loadScheme((utf8*)"TaharezLook.scheme");
mCEGUISystem=System::getSingletonPtr();
mCEGUISystem->setDefaultMouseCursor((utf8*)"TaharezLook", (utf8*)"MouseArrow");
CEGUI::Font *font;
if(!CEGUI::FontManager::getSingleton().isFontPresent("Commonwealth-10"))
{
font = CEGUI::FontManager::getSingleton().createFont( "Commonwealth-10.font" );
}
else
{
font=CEGUI::FontManager::getSingleton().getFont("Commonwealth-10");
}
mCEGUIWindowManager=CEGUI::WindowManager::getSingletonPtr();
Window* rootWindow = mCEGUIWindowManager->loadWindowLayout(filename.c_str());
mCEGUISystem->setGUISheet(rootWindow);
rootWindow->setMouseCursor("TaharezLook", "MouseArrow");
rootWindow->show();
}
catch(CEGUI::Exception &c){}
{
//no gui will be drawn
}
}
and heres the destructor...
Code: Select all
MainApplication::~MainApplication()
{
//SDL_FreeSurface(mScreen);
if(mClock)
delete(mClock);
if(CEGUI::System::getSingletonPtr())
delete CEGUI::System::getSingletonPtr();
if(mOpenGLRenderer)
delete(mOpenGLRenderer);
}
for creating windows in code, the openGL demo shows some examples of random widget creation. hope some of this helps, its a bit disorgonized... but, its all i really have at the moment. good luck
also, its almost st patricks day, so
- CrazyEddie
- CEGUI Project Lead
- Posts: 6760
- Joined: Wed Jan 12, 2005 12:06
- Location: England
- Contact:
Re: OpenGL Renderer without GLUT
wingdongdoodle wrote:
also, its almost st patricks day, so
Re: OpenGL Renderer without GLUT
I am not successful in this so far. I did everything suggested by wingdongdoodle, but I am still having no luck. All I get is a black screen. It could possibly have something to do with this (taken from CEGUI.log)..
Thanks in advance!
Nikon
18/03/2005 02:58:13 (Error) Exception: Font::defineFontGlyphs_impl - operation requires a texture larger than the supported maximum.
Thanks in advance!
Nikon
- CrazyEddie
- CEGUI Project Lead
- Posts: 6760
- Joined: Wed Jan 12, 2005 12:06
- Location: England
- Contact:
Re: OpenGL Renderer without GLUT
Almost certainly this is the problem.
What gfx card do you have and what font are you creating, at what resolution, and does the font have 'auto-scaling' enabled?
CE.
What gfx card do you have and what font are you creating, at what resolution, and does the font have 'auto-scaling' enabled?
CE.
Useful Links: Forum Guidelines | Documentation | Tutorials | HOWTO | Videos | Donate to CEGUI | CEGUI Twitter
Re: OpenGL Renderer without GLUT
I am trying to build size 8 tahoma (as well as 10 and 12). I built and ran the example tutorial that uses GLUT with the same datafiles and xml layout and it worked just fine. As for my gfx card, I have a GF4 MX 400 128mb. It's not great, but it shoudl work.
I have tried some more testing and now it crashes on renderGui() and gives an assertation error that says Expression: ms_Singleton (as well as some other stuff that isn't important).
I have no clue what is wrong .
Thanks in advance!
Nikon
EDIT: I meant MX 440
I have tried some more testing and now it crashes on renderGui() and gives an assertation error that says Expression: ms_Singleton (as well as some other stuff that isn't important).
I have no clue what is wrong .
Thanks in advance!
Nikon
EDIT: I meant MX 440
Re: OpenGL Renderer without GLUT
EDIT: Ok, I got it working. The problem was that I was trying to initialize CEGUI before the window was created. Everything works now .
Nikon
Nikon
- CrazyEddie
- CEGUI Project Lead
- Posts: 6760
- Joined: Wed Jan 12, 2005 12:06
- Location: England
- Contact:
Re: OpenGL Renderer without GLUT
Cool, I'm glad you managed to fiure out the issue. I might normally have been more help, but I've been tied up with other things
CE.
CE.
Useful Links: Forum Guidelines | Documentation | Tutorials | HOWTO | Videos | Donate to CEGUI | CEGUI Twitter
Return to “Modifications / Integrations / Customisations”
Who is online
Users browsing this forum: No registered users and 9 guests