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

prog.uniformLoc("tex"), prog.uniformLoc("tex"),
}, scale) {} }, 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]; } float getScaleX() { return mat_[0]; }


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


Locs locs_; Locs locs_;

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

} }


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


private: private:
Cygnet::GlShader(Cygnet::GlShader::Type::FRAGMENT, fragmentShader)); Cygnet::GlShader(Cygnet::GlShader::Type::FRAGMENT, fragmentShader));
program.use(); program.use();


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


State state{ State state{
.keys{}, .keys{},
ent->draw(state); ent->draw(state);
} }


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

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

glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);


for (auto &entry: queue_) { 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[] = { 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); glVertexAttribPointer(locs_.position, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), vertexes);

Loading…
Cancel
Save