Browse Source

scale individual elements

opengl-renderer-broken
Martin Dørum 3 years ago
parent
commit
3ebcfc6a36

+ 14
- 4
libcygnet/include/cygnet/RenderQueue.h View File

@@ -25,9 +25,17 @@ public:
prog.uniformLoc("tex"),
}, scale) {}

void show(float x, float y, GlTexture &tex) { show(x, y, tex.width(), tex.height(), tex.id()); }
void show(float x, float y, float w, float h, GLuint tex) {
queue_.push_back({ x, y, w * pixScale_, h * pixScale_, tex });
void show(GlTexture &tex, float x, float y) {
show(tex.id(), x, y, 1, 1, tex.width(), tex.height());
}
void show(GlTexture &tex, float x, float y, float sx, float sy) {
show(tex.id(), x, y, sx, sy, tex.width(), tex.height());
}
void show(GlTexture &tex, float x, float y, float sx, float sy, float w, float h) {
show(tex.id(), x, y, sx, sy, w, h);
}
void show(GLuint tex, float x, float y, float sx, float sy, float w, float h) {
queue_.push_back({ tex, x, y, sx, sy, w * pixScale_, h * pixScale_ });
}

float getScaleX() { return mat_[0]; }
@@ -41,8 +49,10 @@ public:

private:
struct Entry {
float x, y, w, h;
GLuint tex;
float x, y;
float sx, sy;
float w, h;
};

Locs locs_;

+ 3
- 3
libcygnet/samples/game/game.cc View File

@@ -74,7 +74,7 @@ public:
}

void draw(State &state) override {
state.q.show(x_, y_, image_.texture());
state.q.show(image_.texture(), x_, y_);
}

private:
@@ -109,7 +109,7 @@ int main() {
Cygnet::GlShader(Cygnet::GlShader::Type::FRAGMENT, fragmentShader));
program.use();

Cygnet::RenderQueue q(program, 1/100.0);
Cygnet::RenderQueue q(program, 1/32.0);

State state{
.keys{},
@@ -165,7 +165,7 @@ int main() {
ent->draw(state);
}

q.setScale(win.xScale(), win.yScale());
q.setScale(win.xScale() * 0.5, win.yScale() * 0.5);
q.draw();
win.flip();
}

+ 8
- 4
libcygnet/src/RenderQueue.cc View File

@@ -28,11 +28,15 @@ void RenderQueue::draw() {
glActiveTexture(GL_TEXTURE0);

for (auto &entry: queue_) {
float w = entry.w * entry.sx;
float h = entry.h * entry.sy;
float x = entry.x;
float y = entry.y;
GLfloat vertexes[] = {
entry.x, entry.y, // top left
entry.x, entry.y + entry.h, // bottom left
entry.x + entry.w, entry.y + entry.h, // bottom right
entry.x + entry.w, entry.y, // top right
x, y, // top left
x, y + h, // bottom left
x + w, y + h, // bottom right
x + w, y, // top right
};

glVertexAttribPointer(locs_.position, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), vertexes);

Loading…
Cancel
Save