Playing with projections.

This commit is contained in:
James Grogan 2022-11-14 16:07:13 +00:00
parent be94bf0185
commit 71b5e8d4b1
2 changed files with 25 additions and 14 deletions

View file

@ -18,15 +18,20 @@ void OpenGlPainter::paint(DrawingContext* context)
auto surface = context->getSurface(); auto surface = context->getSurface();
const auto width = double(surface->getWidth()); const auto width = double(surface->getWidth());
const auto height = double(surface->getHeight()); const auto height = double(surface->getHeight());
std::cout << "Painting into width " << width << " and height " << height << std::endl;
const auto num_mesh = context->getScene()->getNumMeshes(); const auto num_mesh = context->getScene()->getNumMeshes();
glClearColor(1.0, 1.0, 1.0, 0.0); glClearColor(1.0, 1.0, 1.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
//glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); glViewport(0, 0, width, height);
glOrtho(0, width, 0, height, -1.0, 1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//glMatrixMode(GL_MODELVIEW);
//glLoadIdentity();
std::cout << "Bounds are : " << width << " | " << height << std::endl;
for (std::size_t idx=0; idx<num_mesh; idx++) for (std::size_t idx=0; idx<num_mesh; idx++)
{ {
@ -44,23 +49,23 @@ void OpenGlPainter::paint(DrawingContext* context)
glColor3f(r, g, b); glColor3f(r, g, b);
glBegin(GL_TRIANGLES); glBegin(GL_TRIANGLES);
double x0 = 2.0*face[0].getX() / width - 1.0; double x0 = face[0].getX();
double y0 = 1.0 - 2.0*face[0].getY() / height; double y0 = height -face[0].getY();
double x1 = 2.0*face[1].getX() / width - 1.0; double x1 = face[1].getX();
double y1 = 1.0 - 2.0*face[1].getY() / height; double y1 = height -face[1].getY();
double x2 = 2.0*face[2].getX() / width - 1.0; double x2 = face[2].getX();
double y2 = 1.0 - 2.0*face[2].getY() / height; double y2 = height -face[2].getY();
glVertex3f(x0, y0, 0); glVertex3f(x0, y0, 0);
glVertex3f(x1, y1, 0); glVertex3f(x1, y1, 0);
glVertex3f(x2, y2, 0); glVertex3f(x2, y2, 0);
// std::cout << "Verts0| " << x0 << " | " << y0 << " | "<< std::endl; std::cout << "Verts0| " << x0 << " | " << y0 << " | "<< std::endl;
// std::cout << "Verts1| " << x1 << " | " << y1 << " | "<< std::endl; std::cout << "Verts1| " << x1 << " | " << y1 << " | "<< std::endl;
// std::cout << "Verts2| " << x2 << " | " << y2 << " | "<< std::endl; std::cout << "Verts2| " << x2 << " | " << y2 << " | "<< std::endl;
// std::cout << "****************" << std::endl; std::cout << "****************" << std::endl;
glEnd(); glEnd();

View file

@ -60,6 +60,12 @@ bool XcbGlWindowInterface::initialize(xcb_window_t window)
void XcbGlWindowInterface::resizeViewPort(unsigned width, unsigned height) void XcbGlWindowInterface::resizeViewPort(unsigned width, unsigned height)
{ {
glViewport(0, 0, width, height); glViewport(0, 0, width, height);
glOrtho(0, width, 0, height, -1.0, 1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//glMatrixMode(GL_MODELVIEW);
} }
void XcbGlWindowInterface::destroyWindow() void XcbGlWindowInterface::destroyWindow()