Pārlūkot izejas kodu

implement star background

master
cirdan pirms 13 gadiem
vecāks
revīzija
219d5743b8
8 mainītis faili ar 97 papildinājumiem un 53 dzēšanām
  1. +23
    -0
      engine/Material.h
  2. +38
    -42
      engine/RenderDevice.cpp
  3. +8
    -3
      engine/RenderDevice.h
  4. +4
    -2
      engine/RenderQueue.cpp
  5. +1
    -1
      engine/data/main.nut
  6. Binārs
      engine/data/nebular.zip
  7. Binārs
      engine/data/stars.zip
  8. +23
    -5
      engine/main.cpp

+ 23
- 0
engine/Material.h Parādīt failu

@@ -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_*/

+ 38
- 42
engine/RenderDevice.cpp Parādīt failu

@@ -17,7 +17,7 @@ void RenderDevice::WindowResizeSlot(int width, int height)
}

RenderDevice::RenderDevice(RenderWindow* renderWindow) :
_RenderWindow(renderWindow)
_RenderWindow(renderWindow), _ActiveTextures(0)
{
if (_RenderWindow.valid())
{
@@ -32,7 +32,7 @@ RenderDevice::RenderDevice(RenderWindow* renderWindow) :
glViewport( 0, 0, _ViewportWidth, _ViewportHeight);
}

clog << ">>> RenderDevice constructed..."<< endlog;
clog << ">>> RenderDevice constructed..." << endlog;
}

RenderDevice::~RenderDevice()
@@ -114,6 +114,10 @@ void RenderDevice::begin3D(Camera *camera)
setupViewMatrix();
}

void RenderDevice::end3D()
{
}

void RenderDevice::setupProjectionMatrix()
{
if (_Camera.valid())
@@ -132,55 +136,47 @@ void RenderDevice::setupProjectionMatrix()

void RenderDevice::setupViewMatrix()
{
// set the view matrix
glMatrixMode(GL_MODELVIEW);
if (_Camera.valid())
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
Matrix4x4 m(_Camera->getRotation(), _Camera->getRotation().applyInversed(_Camera->getPosition() * -1.0) );
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;
void RenderDevice::pushTransformation(const Vector3& position,
const Quaternion& orientation)
{
glMatrixMode( GL_MODELVIEW);
glPushMatrix();
Matrix4x4 m(orientation, position);
glMultMatrixd( ( GLdouble * ) &m.m );
}

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 );
void RenderDevice::popTransformation()
{
glMatrixMode( GL_MODELVIEW);
glPopMatrix();
}

Vector3 nc = p + d * _near;
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);

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 );
if (unit > _ActiveTextures)
_ActiveTextures = unit;

_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 );
*/
}
if (last)
{
for (unsigned int i = unit + 1; i < _ActiveTextures; i++)
{
glActiveTextureARB(GL_TEXTURE0_ARB + i);
glDisable( GL_TEXTURE_2D);
}

void RenderDevice::setTransformation (const Vector3& position, const Quaternion& orientation)
{
glMatrixMode ( GL_MODELVIEW );
glPushMatrix();
Matrix4x4 m ( orientation, position );
glMultMatrixd ( ( GLdouble * ) &m.m );
_ActiveTextures = unit;
}
}

#if 0
void RenderDevice::setu
// set the view matrix
glMatrixMode (GL_MODELVIEW );
glLoadIdentity();
Matrix4x4 m(_Rotation, _Rotation.applyInversed(_Position * -1.0) );
glMultMatrixd ( ( GLdouble * ) &m.m );
} // namespace BlueCore
#endif
}

+ 8
- 3
engine/RenderDevice.h Parādīt failu

@@ -22,6 +22,8 @@ private:
ref_ptr<RenderWindow> _RenderWindow;
ref_ptr<Camera> _Camera;
unsigned int _ActiveTextures;
public:

RenderDevice(RenderWindow* renderWindow);
@@ -33,15 +35,18 @@ public:
void begin2D();
void end2D();

void begin3D(Camera *);
void end3D();

void clear();
void swap();

void setAmbientLight(float r, float g, float b);
void setMaterial(Material *);

void setTexture(unsigned int unit, unsigned int texture);
void begin3D(Camera *);
void setTransformation (const Vector3&, const Quaternion&);
void setTexture(unsigned int unit, Texture* texture, bool last = false);
void pushTransformation (const Vector3&, const Quaternion&);
void popTransformation ();
void setupProjectionMatrix();
void setupViewMatrix();



+ 4
- 2
engine/RenderQueue.cpp Parādīt failu

@@ -37,14 +37,16 @@ void RenderQueue::render(RenderDevice *device) const
for (i = _OpaqueItems.begin(); i != _OpaqueItems.end(); i++)
{
device->setTransformation((*i).position, (*i).orientation);
device->pushTransformation((*i).position, (*i).orientation);
(*i).item->render(device);
device->popTransformation();
}
for (i = _TransparentItems.begin(); i != _TransparentItems.end(); i++)
{
device->setTransformation((*i).position, (*i).orientation);
device->pushTransformation((*i).position, (*i).orientation);
(*i).item->render(device);
device->popTransformation();
}
}


+ 1
- 1
engine/data/main.nut Parādīt failu

@@ -74,7 +74,7 @@ body <- null;
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);
::body = RigidBody();


Binārs
engine/data/nebular.zip Parādīt failu


Binārs
engine/data/stars.zip Parādīt failu


+ 23
- 5
engine/main.cpp Parādīt failu

@@ -89,10 +89,6 @@ int main(int argc, char **argv)
ref_ptr<Camera> camera = new Camera();
ref_ptr<RenderQueue> queue = new RenderQueue();

/*
ShaderProgram prog =
shadermanager->loadShaderProgram("ambient_color_emissive");
*/
setupScriptSystem_Font(scriptsystem, fontmanager);
setupScriptSystem_Image(scriptsystem, texturemanager, device);
setupScriptSystem_Math(scriptsystem);
@@ -107,6 +103,12 @@ int main(int argc, char **argv)
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
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())
{
scriptsystem->loadScript("main");
@@ -114,7 +116,7 @@ int main(int argc, char **argv)
camera->setFoV(90.0);
camera->setAspectRatio((double)width/(double)height);
camera->setNearPlane(1.0);
camera->setFarPlane(100.0);
camera->setFarPlane(15000.0);
camera->setPosition(Vector3(0.0, 0.0, 20.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->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->setTexture (stage, name, texture)
// device->clearTextures (stage+1);


Notiek ielāde…
Atcelt
Saglabāt