Skip to content

Commit 7a1a13c

Browse files
committed
Add jgl with resize
1 parent ae5ab35 commit 7a1a13c

11 files changed

Lines changed: 53 additions & 33 deletions

File tree

‎include/vendored/jGL/Display/desktopDisplay.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,15 @@ namespace jGL
407407
glfwSetWindowPos(glfwWindow, s.x, s.y);
408408
}
409409
}
410+
411+
void setResolution(glm::ivec2 wh)
412+
{
413+
resolution = wh;
414+
if (glfwWindow != NULL)
415+
{
416+
glfwSetWindowSize(glfwWindow, resolution.x*main_scale, resolution.y*main_scale);
417+
}
418+
}
410419

411420
void initImgui()
412421
{

‎include/vendored/jGL/Display/display.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ namespace jGL
2525
unsigned getResX() const { return resolution.x; }
2626
unsigned getResY() const { return resolution.y; }
2727
glm::ivec2 getRes() const { return resolution; }
28+
virtual void setResolution(glm::ivec2 wh) { resolution = wh; }
2829

2930
virtual void setFrameLimit(unsigned fps)
3031
{

‎include/vendored/jGL/OpenGL/Text/glTextRenderer.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace jGL::GL
1616

1717
public:
1818

19-
TextRenderer(glm::vec2 res);
19+
TextRenderer();
2020

2121
~TextRenderer()
2222
{
@@ -85,7 +85,6 @@ namespace jGL::GL
8585
std::vector<float> vertices;
8686

8787
glm::mat4 projection;
88-
glm::vec2 res;
8988

9089

9190
void setBufferSize(uint16_t s);

‎include/vendored/jGL/OpenGL/openGLInstance.h‎

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,27 @@ namespace jGL::GL
1616

1717
class OpenGLInstance : public jGLInstance
1818
{
19-
19+
2020
public:
2121

2222
OpenGLInstance(glm::ivec2 res, uint8_t msaa = 0)
23-
: jGLInstance(res),
23+
: jGLInstance(res),
2424
framebuffer(glDrawFramebuffer()),
25-
textRenderer(res)
25+
textRenderer()
2626
{
2727
framebuffer.setResolution
2828
(
2929
res
3030
);
3131
framebuffer.setMSAA(msaa);
32+
setTextProjection(glm::ortho(0.0,double(resolution.x),0.0,double(resolution.y)));
3233
}
3334

34-
~OpenGLInstance(){framebuffer.destroy();}
35+
~OpenGLInstance()
36+
{
37+
if (glIsBuffer(rbo)) { glDeleteRenderbuffers(1, &rbo); }
38+
framebuffer.destroy();
39+
}
3540

3641
void beginFrame(){framebuffer.bind();}
3742
void endFrame(){framebuffer.blit();}
@@ -40,7 +45,7 @@ namespace jGL::GL
4045

4146
void text
4247
(
43-
std::string characters,
48+
std::string characters,
4449
glm::vec2 position,
4550
float scale,
4651
glm::vec4 colour,
@@ -57,26 +62,45 @@ namespace jGL::GL
5762

5863
void setMSAA(uint8_t samples)
5964
{
65+
if (samples == 0) { msaaSamples = 0; return; }
6066
GLint maxSamples;
6167
glGetIntegerv(GL_MAX_SAMPLES, &maxSamples);
6268

6369
if (samples > maxSamples){samples = maxSamples;}
6470

71+
msaaSamples = samples;
72+
6573
framebuffer.setMSAA(samples);
74+
75+
if (glIsBuffer(rbo)) { glDeleteRenderbuffers(1, &rbo); }
76+
glGenRenderbuffers(1, &rbo);
77+
glBindRenderbuffer(GL_RENDERBUFFER, rbo);
78+
glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaaSamples, GL_DEPTH24_STENCIL8, resolution.x, resolution.y);
79+
glBindRenderbuffer(GL_RENDERBUFFER, 0);
80+
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rbo);
81+
}
82+
83+
void setResolution(glm::ivec2 wh)
84+
{
85+
resolution = wh;
86+
framebuffer.setResolution(resolution);
87+
setMSAA(msaaSamples);
88+
setTextProjection(glm::ortho(0.0,double(resolution.x),0.0,double(resolution.y)));
89+
glViewport(0.0f, 0.0f, resolution.x, resolution.y);
6690
}
6791

6892
void setClear(glm::vec4 colour) { clearColour = colour; }
6993
void setProjection(glm::mat4 proj) {/*TODO*/}
7094
void setTextProjection(glm::mat4 proj) { textRenderer.setProjection(proj); }
7195
void setViewport(glm::vec4 view) { glViewport(view.x, view.y, view.z, view.w); }
72-
73-
std::shared_ptr<Particles> createParticles(size_t sizeHint)
96+
97+
std::shared_ptr<Particles> createParticles(size_t sizeHint)
7498
{
75-
return std::static_pointer_cast<Particles>(std::make_shared<glParticles>(sizeHint));
99+
return std::static_pointer_cast<Particles>(std::make_shared<glParticles>(sizeHint));
76100
}
77101

78-
std::shared_ptr<Texture> createTexture(std::filesystem::path imageFile, Texture::Type type)
79-
{
102+
std::shared_ptr<Texture> createTexture(std::filesystem::path imageFile, Texture::Type type)
103+
{
80104
switch (type)
81105
{
82106
case Texture::Type::RGB:
@@ -85,11 +109,11 @@ namespace jGL::GL
85109
return std::static_pointer_cast<Texture>(std::make_shared<glTexture2DRGBA>(imageFile));
86110
default:
87111
return std::static_pointer_cast<Texture>(std::make_shared<glTexture2DRGB>(imageFile));
88-
}
112+
}
89113
}
90114

91115
std::shared_ptr<Texture> createTexture(std::vector<std::byte> data, Texture::Type type)
92-
{
116+
{
93117
switch (type)
94118
{
95119
case Texture::Type::RGB:
@@ -98,7 +122,7 @@ namespace jGL::GL
98122
return std::static_pointer_cast<Texture>(std::make_shared<glTexture2DRGBA>(data));
99123
default:
100124
return std::static_pointer_cast<Texture>(std::make_shared<glTexture2DRGB>(data));
101-
}
125+
}
102126
}
103127

104128
std::shared_ptr<SpriteRenderer> createSpriteRenderer(size_t sizeHint)
@@ -132,6 +156,8 @@ namespace jGL::GL
132156
TextRenderer textRenderer;
133157

134158
glm::vec4 clearColour = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f);
159+
160+
GLuint rbo;
135161
};
136162
}
137163

‎include/vendored/jGL/Vulkan/vulkanInstance.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ namespace jGL::Vulkan
7171
void clear() {/*TODO*/}
7272

7373
void setMSAA(uint8_t samples) {/*TODO*/}
74-
74+
void setResolution(glm::ivec2 wh) {/*TODO*/}
7575
void setClear(glm::vec4 colour) {/*TODO*/}
7676
void setProjection(glm::mat4 proj) {/*TODO*/}
7777
void setTextProjection(glm::mat4 p) {textRenderer->setProjection(p);}

‎include/vendored/jGL/jGL.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ namespace jGL
4747
virtual void setProjection(glm::mat4 proj) = 0;
4848
virtual void setTextProjection(glm::mat4 proj) = 0;
4949
virtual void setViewport(glm::vec4 view) = 0;
50+
virtual void setResolution(glm::ivec2 wh) = 0;
5051

5152
virtual void setMSAA(uint8_t samples) {msaaSamples = samples;}
5253

‎include/vendored/jGL/orthoCam.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ namespace jGL
105105
void setPosition(glm::vec2 newPosition){position=newPosition; update();}
106106
void setPosition(float x, float y){position=glm::vec2(x,y); update();}
107107
void move(float dx, float dy){position += glm::vec2(dx,dy); update();}
108+
void setResolution(glm::ivec2 wh){resolution = wh; update();}
108109

109110
private:
110111

‎lib/libjGL-linux-x86_64.a‎

6.19 KB
Binary file not shown.

‎lib/libjGL-macos.a‎

2.01 KB
Binary file not shown.

‎lib/libjGL-windows.a‎

7.42 KB
Binary file not shown.

0 commit comments

Comments
 (0)