skybox: added moon and stars
This commit is contained in:
@@ -134,9 +134,9 @@ void Batch3D::sprite(vec3 pos, vec3 up, vec3 right, float w, float h, const UVRe
|
||||
uv.u2, uv.v2,
|
||||
r,g,b,a);
|
||||
|
||||
vertex(pos.x - right.x * w - up.x * h,
|
||||
pos.y + right.y * w + up.y * h,
|
||||
pos.z - right.z * w - up.z * h,
|
||||
vertex(pos.x - right.x * w + up.x * h,
|
||||
pos.y - right.y * w + up.y * h,
|
||||
pos.z - right.z * w + up.z * h,
|
||||
uv.u1, uv.v2,
|
||||
r,g,b,a);
|
||||
|
||||
@@ -146,9 +146,9 @@ void Batch3D::sprite(vec3 pos, vec3 up, vec3 right, float w, float h, const UVRe
|
||||
uv.u1, uv.v1,
|
||||
r,g,b,a);
|
||||
|
||||
vertex(pos.x + right.x * w + up.x * h,
|
||||
pos.y - right.y * w - up.y * h,
|
||||
pos.z + right.z * w + up.z * h,
|
||||
vertex(pos.x + right.x * w - up.x * h,
|
||||
pos.y + right.y * w - up.y * h,
|
||||
pos.z + right.z * w - up.z * h,
|
||||
uv.u2, uv.v1,
|
||||
r,g,b,a);
|
||||
|
||||
@@ -178,8 +178,18 @@ void Batch3D::blockCube(const vec3 size, const UVRegion(&texfaces)[6], const vec
|
||||
face(coord+vec3(size.x, 0.0f, 0.0f), size.z, size.y, vec3(0, 0, -1), vec3(0, 1, 0), texfaces[1], (shading ? do_tint(0.9f)*tint : tint));
|
||||
}
|
||||
|
||||
void Batch3D::point(glm::vec3 coord, glm::vec4 tint) {
|
||||
vertex(coord, glm::vec2(), tint.r, tint.g, tint.b, tint.a);
|
||||
}
|
||||
|
||||
void Batch3D::flush() {
|
||||
mesh->reload(buffer, index / B3D_VERTEX_SIZE);
|
||||
mesh->draw();
|
||||
index = 0;
|
||||
}
|
||||
|
||||
void Batch3D::flushPoints() {
|
||||
mesh->reload(buffer, index / B3D_VERTEX_SIZE);
|
||||
mesh->draw(GL_POINTS);
|
||||
index = 0;
|
||||
}
|
||||
|
||||
@@ -43,7 +43,9 @@ public:
|
||||
void sprite(glm::vec3 pos, glm::vec3 up, glm::vec3 right, float w, float h, const UVRegion& uv, glm::vec4 tint);
|
||||
void xSprite(float w, float h, const UVRegion& uv, const glm::vec4 tint, bool shading=true);
|
||||
void blockCube(const glm::vec3 size, const UVRegion(&texfaces)[6], const glm::vec4 tint, bool shading=true);
|
||||
void point(glm::vec3 pos, glm::vec4 tint);
|
||||
void flush();
|
||||
void flushPoints();
|
||||
};
|
||||
|
||||
#endif /* GRAPHICS_BATCH3D_H_ */
|
||||
|
||||
@@ -11,6 +11,9 @@ GfxContext::GfxContext(const GfxContext* parent, Viewport& viewport, Batch2D* g2
|
||||
GfxContext::~GfxContext() {
|
||||
if (parent == nullptr)
|
||||
return;
|
||||
if (depthMask_ != parent->depthMask_) {
|
||||
glDepthMask(parent->depthMask_);
|
||||
}
|
||||
if (depthTest_ != parent->depthTest_) {
|
||||
if (depthTest_) glDisable(GL_DEPTH_TEST);
|
||||
else glEnable(GL_DEPTH_TEST);
|
||||
@@ -19,6 +22,9 @@ GfxContext::~GfxContext() {
|
||||
if (cullFace_) glDisable(GL_CULL_FACE);
|
||||
else glEnable(GL_CULL_FACE);
|
||||
}
|
||||
if (blendMode_ != parent->blendMode_) {
|
||||
Window::setBlendMode(parent->blendMode_);
|
||||
}
|
||||
}
|
||||
|
||||
const Viewport& GfxContext::getViewport() const {
|
||||
@@ -36,11 +42,18 @@ GfxContext GfxContext::sub() const {
|
||||
return ctx;
|
||||
}
|
||||
|
||||
void GfxContext::depthMask(bool flag) {
|
||||
if (depthMask_ == flag)
|
||||
return;
|
||||
depthMask_ = flag;
|
||||
glDepthMask(GL_FALSE + flag);
|
||||
}
|
||||
|
||||
void GfxContext::depthTest(bool flag) {
|
||||
if (depthTest_ == flag)
|
||||
return;
|
||||
depthTest_ = flag;
|
||||
if (depthTest_) {
|
||||
if (flag) {
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
} else {
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
@@ -51,9 +64,16 @@ void GfxContext::cullFace(bool flag) {
|
||||
if (cullFace_ == flag)
|
||||
return;
|
||||
cullFace_ = flag;
|
||||
if (cullFace_) {
|
||||
if (flag) {
|
||||
glEnable(GL_CULL_FACE);
|
||||
} else {
|
||||
glDisable(GL_CULL_FACE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GfxContext::blendMode(blendmode mode) {
|
||||
if (blendMode_ == mode)
|
||||
return;
|
||||
blendMode_ = mode;
|
||||
Window::setBlendMode(mode);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "../typedefs.h"
|
||||
#include "Viewport.h"
|
||||
#include "../window/Window.h"
|
||||
|
||||
class Batch2D;
|
||||
|
||||
@@ -10,8 +11,10 @@ class GfxContext {
|
||||
const GfxContext* parent;
|
||||
Viewport& viewport;
|
||||
Batch2D* const g2d;
|
||||
bool depthMask_ = true;
|
||||
bool depthTest_ = false;
|
||||
bool cullFace_ = false;
|
||||
blendmode blendMode_ = blendmode::normal;
|
||||
public:
|
||||
GfxContext(const GfxContext* parent, Viewport& viewport, Batch2D* g2d);
|
||||
~GfxContext();
|
||||
@@ -20,8 +23,10 @@ public:
|
||||
const Viewport& getViewport() const;
|
||||
GfxContext sub() const;
|
||||
|
||||
void depthMask(bool flag);
|
||||
void depthTest(bool flag);
|
||||
void cullFace(bool flag);
|
||||
void blendMode(blendmode mode);
|
||||
};
|
||||
|
||||
#endif // GRAPHICS_GFX_CONTEXT_H_
|
||||
@@ -46,6 +46,13 @@ ImageData* Texture::readData() {
|
||||
return new ImageData(ImageFormat::rgba8888, width, height, data.release());
|
||||
}
|
||||
|
||||
void Texture::setNearestFilter() {
|
||||
bind();
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
Texture* Texture::from(const ImageData* image) {
|
||||
uint width = image->getWidth();
|
||||
uint height = image->getHeight();
|
||||
|
||||
@@ -18,6 +18,8 @@ public:
|
||||
void bind();
|
||||
void reload(ubyte* data);
|
||||
|
||||
void setNearestFilter();
|
||||
|
||||
ImageData* readData();
|
||||
|
||||
static Texture* from(const ImageData* image);
|
||||
|
||||
Reference in New Issue
Block a user