implement star background
This commit is contained in:
parent
a3c60c20f1
commit
219d5743b8
23
engine/Material.h
Normal file
23
engine/Material.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#ifndef BLUECORE_MATERIAL_H
|
||||||
|
#define BLUECORE_MATERIAL_H
|
||||||
|
|
||||||
|
#include "ShaderManager.h"
|
||||||
|
#include "TextureManager.h"
|
||||||
|
|
||||||
|
namespace BlueCore
|
||||||
|
{
|
||||||
|
|
||||||
|
class Material
|
||||||
|
{
|
||||||
|
typedef ref_ptr<Texture> TexturePtr;
|
||||||
|
typedef std::pair<std::string, TexturePtr> TextureUnit;
|
||||||
|
|
||||||
|
std::vector<TextureUnit> _Textures;
|
||||||
|
ShaderProgram _ShaderProgram;
|
||||||
|
bool Tangents;
|
||||||
|
float Shininess;
|
||||||
|
float Specular[4];
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif /*MATERIAL_H_*/
|
@ -17,7 +17,7 @@ void RenderDevice::WindowResizeSlot(int width, int height)
|
|||||||
}
|
}
|
||||||
|
|
||||||
RenderDevice::RenderDevice(RenderWindow* renderWindow) :
|
RenderDevice::RenderDevice(RenderWindow* renderWindow) :
|
||||||
_RenderWindow(renderWindow)
|
_RenderWindow(renderWindow), _ActiveTextures(0)
|
||||||
{
|
{
|
||||||
if (_RenderWindow.valid())
|
if (_RenderWindow.valid())
|
||||||
{
|
{
|
||||||
@ -114,6 +114,10 @@ void RenderDevice::begin3D(Camera *camera)
|
|||||||
setupViewMatrix();
|
setupViewMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RenderDevice::end3D()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void RenderDevice::setupProjectionMatrix()
|
void RenderDevice::setupProjectionMatrix()
|
||||||
{
|
{
|
||||||
if (_Camera.valid())
|
if (_Camera.valid())
|
||||||
@ -132,41 +136,15 @@ void RenderDevice::setupProjectionMatrix()
|
|||||||
|
|
||||||
void RenderDevice::setupViewMatrix()
|
void RenderDevice::setupViewMatrix()
|
||||||
{
|
{
|
||||||
// set the view matrix
|
if (_Camera.valid())
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
Matrix4x4 m(_Camera->getRotation(), _Camera->getRotation().applyInversed(_Camera->getPosition() * -1.0) );
|
Matrix4x4 m(_Camera->getRotation(), _Camera->getRotation().applyInversed(_Camera->getPosition() * -1.0) );
|
||||||
glMultMatrixd( ( GLdouble * ) &m.m );
|
glMultMatrixd( ( GLdouble * ) &m.m );
|
||||||
/*
|
|
||||||
// calculate frustum planes
|
|
||||||
Vector3 up = q.apply ( Vector3 ( 0.0, 1.0, 0.0 ) );
|
|
||||||
Vector3 right = q.apply ( Vector3 ( 1.0, 0.0, 0.0 ) );
|
|
||||||
Vector3 d = q.apply ( Vector3 ( 0.0, 0.0, -1.0 ) );
|
|
||||||
|
|
||||||
Vector3 fc = p + d * _far;
|
|
||||||
|
|
||||||
Vector3 ftl = fc + ( up * _hFar ) - ( right * _wFar );
|
|
||||||
Vector3 ftr = fc + ( up * _hFar ) + ( right * _wFar );
|
|
||||||
Vector3 fbl = fc - ( up * _hFar ) - ( right * _wFar );
|
|
||||||
Vector3 fbr = fc - ( up * _hFar ) + ( right * _wFar );
|
|
||||||
|
|
||||||
Vector3 nc = p + d * _near;
|
|
||||||
|
|
||||||
Vector3 ntl = nc + ( up * _hNear ) - ( right * _wNear );
|
|
||||||
Vector3 ntr = nc + ( up * _hNear ) + ( right * _wNear );
|
|
||||||
Vector3 nbl = nc - ( up * _hNear ) - ( right * _wNear );
|
|
||||||
Vector3 nbr = nc - ( up * _hNear ) + ( right * _wNear );
|
|
||||||
|
|
||||||
_frustumPlanes[RightPlane] = Plane ( nbr, fbr, ntr );
|
|
||||||
_frustumPlanes[LeftPlane] = Plane ( ntl, fbl, nbl );
|
|
||||||
_frustumPlanes[BottomPlane] = Plane ( nbl, fbr, nbr );
|
|
||||||
_frustumPlanes[TopPlane] = Plane ( ntr, ftl, ntl );
|
|
||||||
_frustumPlanes[FarPlane] = Plane ( ftl, ftr, fbl );
|
|
||||||
_frustumPlanes[NearPlane] = Plane ( ntl, nbl, ntr );
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderDevice::setTransformation (const Vector3& position, const Quaternion& orientation)
|
void RenderDevice::pushTransformation(const Vector3& position,
|
||||||
|
const Quaternion& orientation)
|
||||||
{
|
{
|
||||||
glMatrixMode( GL_MODELVIEW);
|
glMatrixMode( GL_MODELVIEW);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
@ -174,13 +152,31 @@ void RenderDevice::setTransformation (const Vector3& position, const Quaternion&
|
|||||||
glMultMatrixd( ( GLdouble * ) &m.m );
|
glMultMatrixd( ( GLdouble * ) &m.m );
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
void RenderDevice::popTransformation()
|
||||||
void RenderDevice::setu
|
{
|
||||||
// set the view matrix
|
|
||||||
glMatrixMode( GL_MODELVIEW);
|
glMatrixMode( GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glPopMatrix();
|
||||||
Matrix4x4 m(_Rotation, _Rotation.applyInversed(_Position * -1.0) );
|
|
||||||
glMultMatrixd ( ( GLdouble * ) &m.m );
|
|
||||||
} // namespace BlueCore
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RenderDevice::setTexture(unsigned int unit, Texture* texture, bool last)
|
||||||
|
{
|
||||||
|
glActiveTextureARB(GL_TEXTURE0_ARB + unit);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, texture->getId());
|
||||||
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
|
||||||
|
if (unit > _ActiveTextures)
|
||||||
|
_ActiveTextures = unit;
|
||||||
|
|
||||||
|
if (last)
|
||||||
|
{
|
||||||
|
for (unsigned int i = unit + 1; i < _ActiveTextures; i++)
|
||||||
|
{
|
||||||
|
glActiveTextureARB(GL_TEXTURE0_ARB + i);
|
||||||
|
glDisable( GL_TEXTURE_2D);
|
||||||
|
}
|
||||||
|
|
||||||
|
_ActiveTextures = unit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace BlueCore
|
||||||
|
@ -22,6 +22,8 @@ private:
|
|||||||
ref_ptr<RenderWindow> _RenderWindow;
|
ref_ptr<RenderWindow> _RenderWindow;
|
||||||
ref_ptr<Camera> _Camera;
|
ref_ptr<Camera> _Camera;
|
||||||
|
|
||||||
|
unsigned int _ActiveTextures;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
RenderDevice(RenderWindow* renderWindow);
|
RenderDevice(RenderWindow* renderWindow);
|
||||||
@ -33,15 +35,18 @@ public:
|
|||||||
void begin2D();
|
void begin2D();
|
||||||
void end2D();
|
void end2D();
|
||||||
|
|
||||||
|
void begin3D(Camera *);
|
||||||
|
void end3D();
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
void swap();
|
void swap();
|
||||||
|
|
||||||
void setAmbientLight(float r, float g, float b);
|
void setAmbientLight(float r, float g, float b);
|
||||||
void setMaterial(Material *);
|
void setMaterial(Material *);
|
||||||
|
|
||||||
void setTexture(unsigned int unit, unsigned int texture);
|
void setTexture(unsigned int unit, Texture* texture, bool last = false);
|
||||||
void begin3D(Camera *);
|
void pushTransformation (const Vector3&, const Quaternion&);
|
||||||
void setTransformation (const Vector3&, const Quaternion&);
|
void popTransformation ();
|
||||||
void setupProjectionMatrix();
|
void setupProjectionMatrix();
|
||||||
void setupViewMatrix();
|
void setupViewMatrix();
|
||||||
|
|
||||||
|
@ -37,14 +37,16 @@ void RenderQueue::render(RenderDevice *device) const
|
|||||||
|
|
||||||
for (i = _OpaqueItems.begin(); i != _OpaqueItems.end(); i++)
|
for (i = _OpaqueItems.begin(); i != _OpaqueItems.end(); i++)
|
||||||
{
|
{
|
||||||
device->setTransformation((*i).position, (*i).orientation);
|
device->pushTransformation((*i).position, (*i).orientation);
|
||||||
(*i).item->render(device);
|
(*i).item->render(device);
|
||||||
|
device->popTransformation();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = _TransparentItems.begin(); i != _TransparentItems.end(); i++)
|
for (i = _TransparentItems.begin(); i != _TransparentItems.end(); i++)
|
||||||
{
|
{
|
||||||
device->setTransformation((*i).position, (*i).orientation);
|
device->pushTransformation((*i).position, (*i).orientation);
|
||||||
(*i).item->render(device);
|
(*i).item->render(device);
|
||||||
|
device->popTransformation();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ body <- null;
|
|||||||
|
|
||||||
function Initialize()
|
function Initialize()
|
||||||
{
|
{
|
||||||
::font = Font ("DejaVuSans.ttf", 24, 1 );
|
::font = Font();//Font ("DejaVuSans.ttf", 24, 1 );
|
||||||
::logo = Image ("image.png", 0.0, 0.0, 1.0, 1.0);
|
::logo = Image ("image.png", 0.0, 0.0, 1.0, 1.0);
|
||||||
::body = RigidBody();
|
::body = RigidBody();
|
||||||
|
|
||||||
|
BIN
engine/data/nebular.zip
Normal file
BIN
engine/data/nebular.zip
Normal file
Binary file not shown.
BIN
engine/data/stars.zip
Normal file
BIN
engine/data/stars.zip
Normal file
Binary file not shown.
@ -89,10 +89,6 @@ int main(int argc, char **argv)
|
|||||||
ref_ptr<Camera> camera = new Camera();
|
ref_ptr<Camera> camera = new Camera();
|
||||||
ref_ptr<RenderQueue> queue = new RenderQueue();
|
ref_ptr<RenderQueue> queue = new RenderQueue();
|
||||||
|
|
||||||
/*
|
|
||||||
ShaderProgram prog =
|
|
||||||
shadermanager->loadShaderProgram("ambient_color_emissive");
|
|
||||||
*/
|
|
||||||
setupScriptSystem_Font(scriptsystem, fontmanager);
|
setupScriptSystem_Font(scriptsystem, fontmanager);
|
||||||
setupScriptSystem_Image(scriptsystem, texturemanager, device);
|
setupScriptSystem_Image(scriptsystem, texturemanager, device);
|
||||||
setupScriptSystem_Math(scriptsystem);
|
setupScriptSystem_Math(scriptsystem);
|
||||||
@ -107,6 +103,12 @@ int main(int argc, char **argv)
|
|||||||
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
|
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
|
||||||
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
|
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
|
||||||
|
|
||||||
|
ref_ptr<Mesh> starMesh = meshmanager->loadMesh("stars.3ds");
|
||||||
|
ref_ptr<Texture> starTexture = texturemanager->loadTexture("stars.png", 0);
|
||||||
|
|
||||||
|
ref_ptr<Mesh> nebularMesh = meshmanager->loadMesh("nebular.3ds");
|
||||||
|
ref_ptr<Texture> nebularTexture = texturemanager->loadTexture("nebular.png");
|
||||||
|
|
||||||
if (window.valid() && device.valid())
|
if (window.valid() && device.valid())
|
||||||
{
|
{
|
||||||
scriptsystem->loadScript("main");
|
scriptsystem->loadScript("main");
|
||||||
@ -114,7 +116,7 @@ int main(int argc, char **argv)
|
|||||||
camera->setFoV(90.0);
|
camera->setFoV(90.0);
|
||||||
camera->setAspectRatio((double)width/(double)height);
|
camera->setAspectRatio((double)width/(double)height);
|
||||||
camera->setNearPlane(1.0);
|
camera->setNearPlane(1.0);
|
||||||
camera->setFarPlane(100.0);
|
camera->setFarPlane(15000.0);
|
||||||
camera->setPosition(Vector3(0.0, 0.0, 20.0));
|
camera->setPosition(Vector3(0.0, 0.0, 20.0));
|
||||||
|
|
||||||
device->setAmbientLight(1.0, 1.0, 1.0);
|
device->setAmbientLight(1.0, 1.0, 1.0);
|
||||||
@ -142,6 +144,22 @@ int main(int argc, char **argv)
|
|||||||
queue->addOpaqueItem(model, Vector3(10.0, 0.0, 0.0), Quaternion(Vector3(0.0,1.0,0.0), fmod(time, 3)));
|
queue->addOpaqueItem(model, Vector3(10.0, 0.0, 0.0), Quaternion(Vector3(0.0,1.0,0.0), fmod(time, 3)));
|
||||||
queue->render(device);
|
queue->render(device);
|
||||||
|
|
||||||
|
|
||||||
|
glMatrixMode ( GL_MODELVIEW );
|
||||||
|
glPushMatrix();
|
||||||
|
glLoadIdentity();
|
||||||
|
glEnable ( GL_BLEND );
|
||||||
|
glBlendFunc ( GL_ONE, GL_ONE );
|
||||||
|
glEnable ( GL_DEPTH_TEST );
|
||||||
|
glDepthMask ( GL_FALSE );
|
||||||
|
glDisable ( GL_LIGHTING );
|
||||||
|
glColor4d ( 1.0f, 1.0f, 1.0f, 1.0f );
|
||||||
|
|
||||||
|
device->setTexture(0, starTexture, true);
|
||||||
|
starMesh->render();
|
||||||
|
glDisable ( GL_BLEND );
|
||||||
|
|
||||||
|
|
||||||
// device->useShader (program);
|
// device->useShader (program);
|
||||||
// device->setTexture (stage, name, texture)
|
// device->setTexture (stage, name, texture)
|
||||||
// device->clearTextures (stage+1);
|
// device->clearTextures (stage+1);
|
||||||
|
Loading…
Reference in New Issue
Block a user