Browse Source

useBoxShader, keep box coords on resize, no need to update indices on resize

pull/2/head
Odilitime 5 years ago
parent
commit
50a93f83b3
  1. 48
      src/graphics/components/InputComponent.cpp

48
src/graphics/components/InputComponent.cpp

@ -11,7 +11,8 @@ InputComponent::InputComponent(const float rawX, const float rawY, const float r @@ -11,7 +11,8 @@ InputComponent::InputComponent(const float rawX, const float rawY, const float r
//std::cout << "InputComponent::InputComponent - data" << std::endl;
//std::cout << "InputComponent::InputComponent - window: " << windowWidth << "x" << windowHeight << " passed " << passedWindowWidth << "x" << passedWindowHeight << std::endl;
boundToPage = true;
//boundToPage = true;
useBoxShader = true;
// set up state
windowWidth = passedWindowWidth;
@ -21,6 +22,9 @@ InputComponent::InputComponent(const float rawX, const float rawY, const float r @@ -21,6 +22,9 @@ InputComponent::InputComponent(const float rawX, const float rawY, const float r
// ugh
x = rawX;
y = rawY;
lastRenderedWindowHeight = windowHeight;
//std::cout << "InputComponent::InputComponent - placing box at " << (int)x << "," << (int)y << " size: " << (int)width << "x" << (int)height << std::endl;
// copy initial state
initialX = x;
@ -47,7 +51,7 @@ InputComponent::InputComponent(const float rawX, const float rawY, const float r @@ -47,7 +51,7 @@ InputComponent::InputComponent(const float rawX, const float rawY, const float r
distanceToViewport(vWidth, vHeight);
//std::cout << "vWidth after: " << (int)vWidth << std::endl;
//std::cout << "placing box at GL " << (int)vx << "x" << (int)vy << " size: " << (int)(vWidth*10000) << "x" << (int)(vHeight*10000) << std::endl;
//std::cout << "InputComponent::InputComponent - placing box at GL " << vx << "," << vy << " to " << vx+vWidth << "," << vy+vHeight << " size: " << vWidth << "x" << vHeight << std::endl;
vertices[(0 * 5) + 0] = vx;
vertices[(0 * 5) + 1] = vy + vHeight;
@ -130,6 +134,8 @@ void InputComponent::render() { @@ -130,6 +134,8 @@ void InputComponent::render() {
}
}
// this doesn't seem to work
// text is fine though
void InputComponent::resize(const int passedWindowWidth, const int passedWindowHeight) {
//std::cout << "InputComponent::resize" << std::endl;
//std::cout << "InputComponent::resize - rasterizing at " << (int)x << "x" << (int)y << " size: " << (int)width << "x" << (int)height << std::endl;
@ -138,19 +144,31 @@ void InputComponent::resize(const int passedWindowWidth, const int passedWindowH @@ -138,19 +144,31 @@ void InputComponent::resize(const int passedWindowWidth, const int passedWindowH
// set up state
windowWidth = passedWindowWidth;
windowHeight = passedWindowHeight;
if (!boundToPage) {
// ok because box shader is anchored to the bottom of the screen
// if we resize Y (increase height), we need to rebind
int yDiff = windowHeight - lastRenderedWindowHeight;
//std::cout << "InputComponent::resize - Adjusting y: " << y << " by " << yDiff << std::endl;
this->y += yDiff;
lastRenderedWindowHeight = windowHeight;
}
// turning this off breaks coordinates
boundToPage = false;
//boundToPage = true;
useBoxShader = true;
for (int i = 0; i < 3; i++) {
data[0][0][i] = 0xf0; // set RGB color
}
data[0][0][3] = 0xff; // set alpha
//std::cout << "InputComponent::resize - placing box at " << (int)x << "," << (int)y << " size: " << (int)width << "x" << (int)height << std::endl;
float vx = x;
float vy = y;
float vx1 = x + width;
float vy1 = y - height;
//float vx1 = x + width;
//float vy1 = y - height;
/*
std::cout << "placing box at " << (int)vx << "," << (int)vy << " size: " << (int)width << "x" << (int)height << " v1: " << (int)vx1 << "," << (int)vy1 << std::endl;
//float vWidth = width;
@ -165,10 +183,19 @@ void InputComponent::resize(const int passedWindowWidth, const int passedWindowH @@ -165,10 +183,19 @@ void InputComponent::resize(const int passedWindowWidth, const int passedWindowH
vx1 = x + width;
vy1 = y - height;
boundToPage = false;
*/
*/
pointToViewport(vx, vy);
pointToViewport(vx1, vy1);
//pointToViewport(vx1, vy1);
float vWidth = width;
float vHeight = height;
distanceToViewport(vWidth, vHeight);
float vx1 = vx + vWidth;
float vy1 = vy + vHeight;
//std::cout << "FALSE placing box at GL v: " << vx << "," << vy << " v1: " << vx1 << "," << vy1 << std::endl;
//std::cout << "InputComponent::resize - placing box at GL " << vx << "," << vy << " to " << vx1 << "," << vy1 << " size: " << vWidth << "x" << vHeight << std::endl;
// converts 512 to 1 and 1 to 2
//std::cout << "vWidth before: " << (int)vWidth << std::endl;
@ -193,13 +220,16 @@ void InputComponent::resize(const int passedWindowWidth, const int passedWindowH @@ -193,13 +220,16 @@ void InputComponent::resize(const int passedWindowWidth, const int passedWindowH
glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObject);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementBufferObject);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
//glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementBufferObject);
//glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
glBindVertexArray(0); // protect what we created against any further modification
//updateText();
if (userInputText) {
userInputText->resize(passedWindowWidth, passedWindowHeight);
}
}
void InputComponent::addChar(char c) {

Loading…
Cancel
Save