GLFW viewport making drawing images a bit wavy when moving the camera down

54 Views Asked by At

I want the GLFW functions to move the drawings appropriately when the window resizes, it does this well but it draws in a wavy way the further the window size is from the resolution size.

here's the code:

//camera movement happens up here

glfwGetWindowSize(window, &window_variables.window_size.width, &window_variables.window_size.height);

glMatrixMode(GL_PROJECTION); 

glLoadIdentity();

glOrtho(0, window_variables.resolution_size.width, window_variables.resolution_size.height, 0, -1, 1);

glMatrixMode(GL_MODELVIEW); 

glLoadIdentity();

glTranslatef(-window_variables.camera.x + window_variables.resolution_size.width / 2, -window_variables.camera.y + window_variables.resolution_size.height / 2, 0.0f);

glViewport(0, 0, window_variables.window_size.width, window_variables.window_size.height);

glClear(GL_COLOR_BUFFER_BIT);

 //more code is written down here, including the drawing of the images using stb_image.h, not very relevant since it works fine in fullscreen mode

//here's the code to draw the object:
void Object::update() 
{
    if (image_data) 
    {
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

        glEnable(GL_TEXTURE_2D);
        glBindTexture(GL_TEXTURE_2D, texture_id);

        Vector_2D position = get_position();
        Size_2D size = get_size();

        float center_x = position.x;
        float center_y = position.y;
        float offset_width = size.width / 2;
        float offset_height = size.height / 2;

        glPushMatrix();
        glTranslatef(center_x, center_y, 0.0f);
        glRotatef(position.angle, 0.0f, 0.0f, 1.0f);
        glTranslatef(-offset_width, -offset_height, 0.0f);

        glBegin(GL_QUADS);
        glColor4f(color.r, color.g, color.b, transparency / 255);
        glTexCoord2f(0, 0);
        glVertex2f(0, 0);
        glTexCoord2f(1, 0);
        glVertex2f(size.width, 0);
        glTexCoord2f(1, 1);
        glVertex2f(size.width, size.height);
        glTexCoord2f(0, 1);
        glVertex2f(0, size.height);
        glEnd();

        glPopMatrix();

        glDisable(GL_TEXTURE_2D);
        glDisable(GL_BLEND);
    }
}

//to draw it I just use object.draw();

am I doing something wrong? or is there a better way to do this?

0

There are 0 best solutions below