Merge revision 4939:4954 from trunk to ogl-es:

- Bugfix: Cloning CBillboardSceneNode now copies colors and sizes.
- Last fix to enable numkeys on X11 had broken the normal DELETE key on X11. So reworked the fix some more.
- Array index was used before limit check
- Add an array with driver name strings for the driver enums.
- Cleaning up Meshviewer example. 
Also added a project target for LinuxGLES2 for the MaterielViewer cbp (this should be done for all examples at some point).


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/branches/ogl-es@4955 dfc29bdd-3216-0410-991c-e03cc46cb475
master
cutealien 2014-10-01 22:02:09 +00:00
parent 36de8ea6a4
commit 43817f07f7
10 changed files with 1147 additions and 835 deletions

View File

@ -8,6 +8,7 @@ Changes in ogl-es (not yet released - will be merged with trunk at some point)
--------------------------
Changes in 1.9 (not yet released)
- Bugfix: Cloning CBillboardSceneNode now copies colors and sizes.
- EditBox works now with numpad on X11
- Added helper functions for converting between wchar and utf-8. Patch provided by Hendu.
- Added sphere frustum culling support. Patch provided by Hendu.

View File

@ -46,6 +46,7 @@
<Add library="Irrlicht" />
</Linker>
<Unit filename="main.cpp" />
<Unit filename="main.h" />
<Extensions>
<code_completion />
<debugger />

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,310 @@
#ifndef EXAMPLE22_MATERIAL_VIEWER_MAIN_H
#define EXAMPLE22_MATERIAL_VIEWER_MAIN_H
#include <irrlicht.h>
// Helper control to allow setting colors
class CColorControl : public irr::gui::IGUIElement
{
public:
CColorControl(irr::gui::IGUIEnvironment* guiEnv, const irr::core::position2d<irr::s32> & pos, const wchar_t *text, irr::gui::IGUIElement* parent, irr::s32 id=-1);
// Event receiver
virtual bool OnEvent(const irr::SEvent &event);
// Set the color values
void setColor(const irr::video::SColor& col);
// Get the color values
const irr::video::SColor& getColor() const
{
return Color;
}
// To reset the dirty flag
void resetDirty()
{
DirtyFlag = false;
}
// when the color was changed the dirty flag is set
bool isDirty() const
{
return DirtyFlag;
};
protected:
// Add a staticbox for a description + an editbox so users can enter numbers
irr::gui::IGUIEditBox* addEditForNumbers(irr::gui::IGUIEnvironment* guiEnv, const irr::core::position2d<irr::s32> & pos, const wchar_t *text, irr::s32 id, irr::gui::IGUIElement * parent);
// Get the color value from the editfields
irr::video::SColor getColorFromEdits() const;
// Fill the editfields with the value for the given color
void setEditsFromColor(irr::video::SColor col);
private:
bool DirtyFlag;
irr::video::SColor Color;
irr::s32 ButtonSetId;
irr::gui::IGUIStaticText * ColorStatic;
irr::gui::IGUIEditBox * EditAlpha;
irr::gui::IGUIEditBox * EditRed;
irr::gui::IGUIEditBox * EditGreen;
irr::gui::IGUIEditBox * EditBlue;
};
/*
Custom GUI-control for to edit all colors typically used in materials and lights
*/
class CTypicalColorsControl : public irr::gui::IGUIElement
{
public:
// Constructor
CTypicalColorsControl(irr::gui::IGUIEnvironment* guiEnv, const irr::core::position2d<irr::s32> & pos, bool hasEmissive, irr::gui::IGUIElement* parent, irr::s32 id=-1);
// Destructor
virtual ~CTypicalColorsControl();
// Set the color values to those within the material
void setColorsToMaterialColors(const irr::video::SMaterial & material);
// Update all changed colors in the material
void updateMaterialColors(irr::video::SMaterial & material) const;
// Set the color values to those from the light data
void setColorsToLightDataColors(const irr::video::SLight & lightData);
// Update all changed colors in the light data
void updateLightColors(irr::video::SLight & lightData) const;
// To reset the dirty flags
void resetDirty();
private:
CColorControl* ControlAmbientColor;
CColorControl* ControlDiffuseColor;
CColorControl* ControlSpecularColor;
CColorControl* ControlEmissiveColor;
};
/*
GUI-Control to offer a selection of available textures.
*/
class CTextureControl : public irr::gui::IGUIElement
{
public:
CTextureControl(irr::gui::IGUIEnvironment* guiEnv, irr::video::IVideoDriver * driver, const irr::core::position2d<irr::s32> & pos, irr::gui::IGUIElement* parent, irr::s32 id=-1);
virtual bool OnEvent(const irr::SEvent &event);
// Workaround for a problem with comboboxes.
// We have to get in front when the combobox wants to get in front or combobox-list might be drawn below other elements.
virtual bool bringToFront(irr::gui::IGUIElement* element);
// Return selected texturename (if any, otherwise 0)
const wchar_t * getSelectedTextureName() const;
// Change active selectionbased on the texture name
void selectTextureByName(const irr::core::stringw& name);
// Reset the dirty flag
void resetDirty()
{
DirtyFlag = false;
}
// When the texture was changed the dirty flag is set
bool isDirty() const
{
return DirtyFlag;
};
// Put the names of all currently loaded textures in a combobox
void updateTextures(irr::video::IVideoDriver * driver);
private:
bool DirtyFlag;
irr::gui::IGUIComboBox * ComboTexture;
};
/*
Control which allows setting some of the material values for a meshscenenode
*/
struct SMaterialControl
{
// constructor
SMaterialControl()
: Initialized(false), Driver(0)
, TypicalColorsControl(0), ButtonLighting(0), InfoLighting(0), ComboMaterial(0)
{
for (irr::u32 i=0; i<irr::video::MATERIAL_MAX_TEXTURES; ++i)
TextureControls[i] = 0;
}
// Destructor
~SMaterialControl()
{
for (irr::u32 i=0; i<irr::video::MATERIAL_MAX_TEXTURES; ++i)
{
if (TextureControls[i] )
TextureControls[i]->drop();
}
if ( TypicalColorsControl )
TypicalColorsControl->drop();
}
void init(irr::scene::IMeshSceneNode* node, irr::IrrlichtDevice * device, const irr::core::position2d<irr::s32> & pos, const wchar_t * description);
void update(irr::scene::IMeshSceneNode* sceneNode, irr::scene::IMeshSceneNode* sceneNode2T, irr::scene::IMeshSceneNode* sceneNodeTangents);
void updateTextures();
void selectTextures(const irr::core::stringw& name);
bool isLightingEnabled() const;
protected:
void updateMaterial(irr::video::SMaterial & material);
bool Initialized;
irr::video::IVideoDriver * Driver;
CTypicalColorsControl* TypicalColorsControl;
irr::gui::IGUIButton * ButtonLighting;
irr::gui::IGUIStaticText* InfoLighting;
irr::gui::IGUIComboBox * ComboMaterial;
CTextureControl* TextureControls[irr::video::MATERIAL_MAX_TEXTURES];
};
/*
Control to allow setting the color values of a lightscenenode.
*/
struct SLightNodeControl
{
// constructor
SLightNodeControl() : Initialized(false), TypicalColorsControl(0)
{}
~SLightNodeControl()
{
if ( TypicalColorsControl )
TypicalColorsControl->drop();
}
void init(irr::scene::ILightSceneNode* node, irr::gui::IGUIEnvironment* guiEnv, const irr::core::position2d<irr::s32> & pos, const wchar_t * description);
void update(irr::scene::ILightSceneNode* node);
protected:
bool Initialized;
CTypicalColorsControl* TypicalColorsControl;
};
/*
Application configuration
*/
struct SConfig
{
SConfig()
: RenderInBackground(true)
, DriverType(irr::video::EDT_NULL)
, ScreenSize(640, 480)
{
}
bool RenderInBackground;
irr::video::E_DRIVER_TYPE DriverType;
irr::core::dimension2d<irr::u32> ScreenSize;
};
/*
Main application class
*/
class CApp : public irr::IEventReceiver
{
friend int main(int argc, char *argv[]);
public:
// constructor
CApp()
: IsRunning(false)
, RealTimeTick(0)
, Device(0)
, MeshManipulator(0)
, Camera(0)
, SceneNode(0), SceneNode2T(0), SceneNodeTangents(0), NodeLight(0)
, LightRotationAxis(irr::core::vector3df(1,0,0))
, ControlVertexColors(0)
, GlobalAmbient(0)
{
memset(KeysPressed, 0, sizeof KeysPressed);
}
// destructor
~CApp()
{
}
// Tell it to stop running
void setRunning(bool appRuns)
{
IsRunning = appRuns;
}
// Check if it should continue running
bool isRunning() const
{
return IsRunning;
}
// Event handler
virtual bool OnEvent(const irr::SEvent &event);
protected:
// Application initialization
// returns true when it was successful initialized, otherwise false.
bool init(int argc, char *argv[]);
// Update one frame
bool update();
// Close down the application
void quit();
// Create some useful textures.
void createDefaultTextures(irr::video::IVideoDriver * driver);
// Load a texture and make sure nodes know it when more textures are available.
void loadTexture(const irr::io::path &name);
// Rotate a node around the origin (0,0,0)
void RotateHorizontal(irr::scene::ISceneNode* node, irr::f32 angle);
void RotateAroundAxis(irr::scene::ISceneNode* node, irr::f32 angle, const irr::core::vector3df& axis);
void ZoomOut(irr::scene::ISceneNode* node, irr::f32 units);
void UpdateRotationAxis(irr::scene::ISceneNode* node, irr::core::vector3df& axis);
private:
SConfig Config;
bool IsRunning;
irr::u32 RealTimeTick;
irr::IrrlichtDevice * Device;
irr::scene::IMeshManipulator* MeshManipulator;
irr::scene::ICameraSceneNode * Camera;
irr::scene::IMeshSceneNode* SceneNode;
irr::scene::IMeshSceneNode* SceneNode2T;
irr::scene::IMeshSceneNode* SceneNodeTangents;
irr::scene::ILightSceneNode* NodeLight;
irr::core::vector3df LightRotationAxis;
SMaterialControl MeshMaterialControl;
SLightNodeControl LightControl;
CColorControl* ControlVertexColors;
CColorControl* GlobalAmbient;
bool KeysPressed[irr::KEY_KEY_CODES_COUNT];
};
#endif

View File

@ -5,6 +5,8 @@
#ifndef __E_DRIVER_TYPES_H_INCLUDED__
#define __E_DRIVER_TYPES_H_INCLUDED__
#include "irrTypes.h"
namespace irr
{
namespace video
@ -62,10 +64,23 @@ namespace video
//! No driver, just for counting the elements
EDT_COUNT
};
const c8* const DRIVER_TYPE_NAMES[] =
{
"NullDriver",
"Software Renderer",
"Burning's Video",
"Direct3D 8.1",
"Direct3D 9.0c",
"OpenGL 1.x/2.x/3.x",
"OpenGL ES1",
"OpenGL ES2",
0
};
} // end namespace video
} // end namespace irr
#endif

View File

@ -8,7 +8,6 @@
#include <iostream>
#include <cstdio>
#include "EDriverTypes.h"
#include "irrTypes.h"
#include "IrrlichtDevice.h"
namespace irr
@ -17,16 +16,12 @@ namespace irr
//! ask user for driver
static irr::video::E_DRIVER_TYPE driverChoiceConsole(bool allDrivers=true)
{
const char* const names[] =
{"NullDriver","Software Renderer","Burning's Video",
"Direct3D 8.1","Direct3D 9.0c",
"OpenGL 1.x-4.x","OpenGL-ES 1.x","OpenGL-ES 2.x"};
printf("Please select the driver you want:\n");
irr::u32 i=0;
for (i=irr::video::EDT_COUNT; i>0; --i)
{
if (allDrivers || (irr::IrrlichtDevice::isDriverSupported(irr::video::E_DRIVER_TYPE(i-1))))
printf(" (%c) %s\n", 'a'+irr::video::EDT_COUNT-i, names[i-1]);
printf(" (%c) %s\n", 'a'+irr::video::EDT_COUNT-i, irr::video::DRIVER_TYPE_NAMES[i-1]);
}
char c;

View File

@ -584,7 +584,7 @@ public:
bool equalsn(const string<T,TAlloc>& other, u32 n) const
{
u32 i;
for(i=0; array[i] && other[i] && i < n; ++i)
for(i=0; i < n && array[i] && other[i]; ++i)
if (array[i] != other[i])
return false;
@ -603,7 +603,7 @@ public:
if (!str)
return false;
u32 i;
for(i=0; array[i] && str[i] && i < n; ++i)
for(i=0; i < n && array[i] && str[i]; ++i)
if (array[i] != str[i])
return false;

View File

@ -281,8 +281,13 @@ ISceneNode* CBillboardSceneNode::clone(ISceneNode* newParent, ISceneManager* new
nb->cloneMembers(this, newManager);
nb->Material = Material;
nb->Size = Size;
nb->TopEdgeWidth = this->TopEdgeWidth;
video::SColor topColor,bottomColor;
getColor(topColor,bottomColor);
nb->setColor(topColor,bottomColor);
if ( newParent )
nb->drop();
return nb;

View File

@ -594,33 +594,8 @@ bool CGUIEditBox::processKey(const SEvent& event)
if ( !isEnabled() )
break;
if (Text.size() != 0)
if (keyDelete())
{
core::stringw s;
if (MarkBegin != MarkEnd)
{
// delete marked text
const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd;
const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin;
s = Text.subString(0, realmbgn);
s.append( Text.subString(realmend, Text.size()-realmend) );
Text = s;
CursorPos = realmbgn;
}
else
{
// delete text before cursor
s = Text.subString(0, CursorPos);
s.append( Text.subString(CursorPos+1, Text.size()-CursorPos-1) );
Text = s;
}
if (CursorPos > (s32)Text.size())
CursorPos = (s32)Text.size();
BlinkStartTime = os::Timer::getTime();
newMarkBegin = 0;
newMarkEnd = 0;
@ -689,6 +664,31 @@ bool CGUIEditBox::processKey(const SEvent& event)
}
break;
case KEY_DELETE:
// At least on X11 we get a char with 127 when the delete key is pressed.
// We get no char when the delete key on numkeys is pressed with numlock off (handled in the other case calling keyDelete as Char is then 0).
// We get a keykode != 127 when delete key on numlock is pressed with numlock on.
if (event.KeyInput.Char == 127)
{
if ( !isEnabled() )
break;
if (keyDelete())
{
BlinkStartTime = os::Timer::getTime();
newMarkBegin = 0;
newMarkEnd = 0;
textChanged = true;
}
break;
}
else
{
inputChar(event.KeyInput.Char);
return true;
}
case KEY_ESCAPE:
case KEY_TAB:
case KEY_SHIFT:
@ -743,6 +743,40 @@ bool CGUIEditBox::processKey(const SEvent& event)
return true;
}
bool CGUIEditBox::keyDelete()
{
if (Text.size() != 0)
{
core::stringw s;
if (MarkBegin != MarkEnd)
{
// delete marked text
const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd;
const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin;
s = Text.subString(0, realmbgn);
s.append( Text.subString(realmend, Text.size()-realmend) );
Text = s;
CursorPos = realmbgn;
}
else
{
// delete text before cursor
s = Text.subString(0, CursorPos);
s.append( Text.subString(CursorPos+1, Text.size()-CursorPos-1) );
Text = s;
}
if (CursorPos > (s32)Text.size())
CursorPos = (s32)Text.size();
return true;
}
return false;
}
//! draws the element and its children
void CGUIEditBox::draw()

View File

@ -162,6 +162,8 @@ namespace gui
void sendGuiEvent(EGUI_EVENT_TYPE type);
//! set text markers
void setTextMarkers(s32 begin, s32 end);
//! delete current selection or next char
bool keyDelete();
bool processKey(const SEvent& event);
bool processMouse(const SEvent& event);