work on the default shader.
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 2m59s
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 2m59s
This commit is contained in:
@@ -47,7 +47,7 @@ if (WIN32)
|
||||
)
|
||||
endif()
|
||||
|
||||
#set(CMAKE_CXX_FLAGS "-O3 -Wall -Wextra")
|
||||
set(CMAKE_CXX_FLAGS "-O3 -Wall -Wextra")
|
||||
|
||||
file(COPY "assets" DESTINATION "${PROJECT_BINARY_DIR}")
|
||||
file(GLOB_RECURSE ASSETS "assets/*")
|
||||
|
@@ -1,7 +1,55 @@
|
||||
#version 120
|
||||
|
||||
// The color manually set with glColor4f, glColor4ubv etc.
|
||||
varying vec4 v_color;
|
||||
|
||||
void main(){
|
||||
// The number of texture units that have been set.
|
||||
uniform int TEXTURE_UNIT_SET_COUNT;
|
||||
|
||||
// True if we should perform the alpha mask operation.
|
||||
uniform bool ALPHA_MASK;
|
||||
|
||||
// True if we're rendering text.
|
||||
uniform bool TEXT;
|
||||
|
||||
// Texture unit 0 - 7 (8 - 31 will come later).
|
||||
uniform sampler2D GL_TEXTURE0;
|
||||
uniform sampler2D GL_TEXTURE1;
|
||||
uniform sampler2D GL_TEXTURE2;
|
||||
uniform sampler2D GL_TEXTURE3;
|
||||
uniform sampler2D GL_TEXTURE4;
|
||||
uniform sampler2D GL_TEXTURE5;
|
||||
uniform sampler2D GL_TEXTURE6;
|
||||
uniform sampler2D GL_TEXTURE7;
|
||||
|
||||
// Texture coordinates.
|
||||
varying vec2 GL_TEXTURE0_COORD;
|
||||
varying vec2 GL_TEXTURE1_COORD;
|
||||
varying vec2 GL_TEXTURE2_COORD;
|
||||
varying vec2 GL_TEXTURE3_COORD;
|
||||
varying vec2 GL_TEXTURE4_COORD;
|
||||
varying vec2 GL_TEXTURE5_COORD;
|
||||
varying vec2 GL_TEXTURE6_COORD;
|
||||
varying vec2 GL_TEXTURE7_COORD;
|
||||
|
||||
void DrawColorOnly() {
|
||||
gl_FragColor = v_color;
|
||||
}
|
||||
|
||||
// TODO fix positive alpha mask.
|
||||
void SampleTextureUnits() {
|
||||
if (TEXT)
|
||||
gl_FragColor = vec4(v_color.rgb, v_color.a * texture2D(GL_TEXTURE0, GL_TEXTURE0_COORD).a);
|
||||
|
||||
// Draw sprite, partial sprite, mirror sprite, render target, partial render target.
|
||||
else if (TEXTURE_UNIT_SET_COUNT == 1)
|
||||
gl_FragColor = v_color * texture2D(GL_TEXTURE0, GL_TEXTURE0_COORD);
|
||||
}
|
||||
|
||||
void main() {
|
||||
if (TEXTURE_UNIT_SET_COUNT == 0) {
|
||||
DrawColorOnly(); return;
|
||||
}
|
||||
|
||||
SampleTextureUnits();
|
||||
}
|
@@ -3,7 +3,27 @@
|
||||
// The color manually set with glColor4f, glColor4ubv etc etc.
|
||||
varying vec4 v_color;
|
||||
|
||||
// The texture coordinates in each texture unit.
|
||||
varying vec2 GL_TEXTURE0_COORD;
|
||||
varying vec2 GL_TEXTURE1_COORD;
|
||||
varying vec2 GL_TEXTURE2_COORD;
|
||||
varying vec2 GL_TEXTURE3_COORD;
|
||||
varying vec2 GL_TEXTURE4_COORD;
|
||||
varying vec2 GL_TEXTURE5_COORD;
|
||||
varying vec2 GL_TEXTURE6_COORD;
|
||||
varying vec2 GL_TEXTURE7_COORD;
|
||||
|
||||
|
||||
void main() {
|
||||
v_color = gl_Color;
|
||||
GL_TEXTURE0_COORD = gl_MultiTexCoord0.xy;
|
||||
GL_TEXTURE1_COORD = gl_MultiTexCoord1.xy;
|
||||
GL_TEXTURE2_COORD = gl_MultiTexCoord2.xy;
|
||||
GL_TEXTURE3_COORD = gl_MultiTexCoord3.xy;
|
||||
GL_TEXTURE4_COORD = gl_MultiTexCoord4.xy;
|
||||
GL_TEXTURE5_COORD = gl_MultiTexCoord5.xy;
|
||||
GL_TEXTURE6_COORD = gl_MultiTexCoord6.xy;
|
||||
GL_TEXTURE7_COORD = gl_MultiTexCoord7.xy;
|
||||
|
||||
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
|
||||
}
|
||||
|
17
main.cpp
17
main.cpp
@@ -133,7 +133,7 @@ public:
|
||||
image = new Texture("assets/sprites/Re3D.png", FilteringMode::MIPMAP_NEAREST, JGL::SampleRate::X16);
|
||||
image_mask = new Texture("assets/sprites/alpha_mask_2.png");
|
||||
j2d_render_target = new RenderTarget({540, 500}, {0,0,0,0}, false,
|
||||
SampleRate::X0, FilteringMode::MIPMAP_TRILINEAR);
|
||||
SampleRate::NONE, FilteringMode::MIPMAP_NEAREST);
|
||||
|
||||
//Texture::MultiplyByAlphaMask(*image, *image_mask);
|
||||
|
||||
@@ -145,7 +145,6 @@ public:
|
||||
float pulse = 0;
|
||||
float sprite_radians = 0;
|
||||
bool fov_increasing = true;
|
||||
int blit_pos = 0;
|
||||
|
||||
void display() {
|
||||
|
||||
@@ -176,7 +175,7 @@ public:
|
||||
camera->render();
|
||||
// All 3D elements of the scene and JGL elements *must* be rendered before the 2D stuff
|
||||
/* if rendering to screen space directly. */
|
||||
auto test_light = PointLight({2,1,2}, {pulse,pulse,pulse, 255}, {pulse, pulse, pulse, 255}, {0,0,0}, 1, 0.1, 0.01);
|
||||
auto test_light = PointLight({2,1,2}, {(u8) pulse,(u8) pulse,(u8) pulse, 255}, {(u8) pulse, (u8) pulse, (u8) pulse, 255}, {0,0,0}, 1, 0.1, 0.01);
|
||||
// If a 3D object has transparency. The things you'd like to see through it must be drawn before.
|
||||
|
||||
J3D::Begin();
|
||||
@@ -191,7 +190,7 @@ public:
|
||||
J3D::WireframeAABB(Colors::Yellow, {0.5, 0, 0.5}, {0.125, 0.125, 0.125}, 1);
|
||||
J3D::End();
|
||||
|
||||
J2D::Begin(nullptr, &shader, true);
|
||||
J2D::Begin(j2d_render_target, &shader, true);
|
||||
J2D::FillRect(Colors::Blue, {0,52}, {100,100});
|
||||
J2D::DrawSprite(image, {300, 400}, sprite_radians * 0.10f, {0.5,0.5}, {1, 1}, Colors::White);
|
||||
J2D::DrawMirrorSprite(image, {400, 300}, Direction::Horizontal | Direction::Vertical, sprite_radians, {0.5,0.5}, {1, 1}, Colors::White);
|
||||
@@ -231,12 +230,12 @@ public:
|
||||
|
||||
J2D::End();
|
||||
|
||||
/*
|
||||
J2D::Begin();
|
||||
//J2D::DrawRenderTarget(j2d_render_target, {0, 0});
|
||||
//J2D::DrawSprite(image, image_mask, {0, 0}, 0.25, {0.5, 0.5}, {1,1});
|
||||
|
||||
J2D::Begin(nullptr, &shader, true);
|
||||
J2D::DrawRenderTarget(j2d_render_target, {0, 0});
|
||||
J2D::DrawSprite(image, image_mask, {0, 0}, 0.25, {0.5, 0.5}, {1,1});
|
||||
J2D::End();
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -427,9 +427,14 @@ void J2D::DrawSprite(const Texture& texture, const Texture& alpha_mask, const Ve
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(Vector2), vertices.data());
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(Vector2), textureCoordinates.data());
|
||||
|
||||
if (current_state.current_shader)
|
||||
current_state.current_shader->SetInt("TEXTURE_UNIT_SET_COUNT", 2);
|
||||
// Draw.
|
||||
glDrawArrays(GL_QUADS, 0, 4);
|
||||
|
||||
if (current_state.current_shader)
|
||||
current_state.current_shader->SetInt("TEXTURE_UNIT_SET_COUNT", 0);
|
||||
|
||||
// Reset Texture 1.
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
@@ -551,11 +556,18 @@ void J2D::DrawSprite(const Texture& texture, const Vector2& pos, float rad_rotat
|
||||
glBindTexture(GL_TEXTURE_2D, texture.GetHandle());
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(Vector2), vertices.data());
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(Vector2), textureCoordinates.data());
|
||||
|
||||
if (current_state.current_shader)
|
||||
current_state.current_shader->SetInt("TEXTURE_UNIT_SET_COUNT", 1);
|
||||
|
||||
glDrawArrays(GL_QUADS, 0, 4);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glColor4fv(default_state.draw_color);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
if (current_state.current_shader)
|
||||
current_state.current_shader->SetInt("TEXTURE_UNIT_SET_COUNT", 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -640,7 +652,15 @@ void J2D::DrawPartialSprite(const Texture& texture, const Vector2& position, con
|
||||
glBindTexture(GL_TEXTURE_2D, texture.GetHandle());
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(Vector2), vertices.data());
|
||||
glTexCoordPointer(2, GL_FLOAT, 0, textureCoordinates.data());
|
||||
|
||||
if (current_state.current_shader)
|
||||
current_state.current_shader->SetInt("TEXTURE_UNIT_SET_COUNT", 1);
|
||||
|
||||
glDrawArrays(GL_QUADS, 0, 4);
|
||||
|
||||
if (current_state.current_shader)
|
||||
current_state.current_shader->SetInt("TEXTURE_UNIT_SET_COUNT", 0);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glColor4fv(default_state.draw_color);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
@@ -722,8 +742,15 @@ void J2D::DrawMirrorSprite(const Texture& texture, const Vector2& position, Dire
|
||||
glColor4ubv(color.ptr());
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(Vector2), vertices.data());
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(Vector2), textureCoordinates.data());
|
||||
|
||||
if (current_state.current_shader)
|
||||
current_state.current_shader->SetInt("TEXTURE_UNIT_SET_COUNT", 1);
|
||||
|
||||
glDrawArrays(GL_QUADS, 0, 4);
|
||||
|
||||
if (current_state.current_shader)
|
||||
current_state.current_shader->SetInt("TEXTURE_UNIT_SET_COUNT", 0);
|
||||
|
||||
//Reset the wrapping mode.
|
||||
if (texture.GetWrappingMode() == WrappingMode::CLAMP_TO_EDGE)
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE),
|
||||
|
@@ -156,7 +156,17 @@ namespace JGL {
|
||||
}
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(Vector2), vertices.data());
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(Vector2), texcoords.data());
|
||||
|
||||
if (current_state.current_shader)
|
||||
current_state.current_shader->SetInt("TEXTURE_UNIT_SET_COUNT", 1),
|
||||
current_state.current_shader->SetBool("TEXT", true);
|
||||
|
||||
glDrawArrays(GL_TRIANGLES, 0, (int) vertices.size() * 6);
|
||||
|
||||
if (current_state.current_shader)
|
||||
current_state.current_shader->SetInt("TEXTURE_UNIT_SET_COUNT", 0),
|
||||
current_state.current_shader->SetBool("TEXT", false);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glColor4fv(default_state.draw_color);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
@@ -238,8 +248,14 @@ namespace JGL {
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
|
||||
if (current_state.current_shader)
|
||||
current_state.current_shader->SetBool("TEXT", true);
|
||||
|
||||
glDrawArrays(GL_TRIANGLES, 0, (int) vertices.size() * 6);
|
||||
|
||||
if (current_state.current_shader)
|
||||
current_state.current_shader->SetBool("TEXT", false);
|
||||
|
||||
if (!draw_back_face)
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
|
Reference in New Issue
Block a user