c++ - OpenGL Rendering Constricted to bottom left quarter of the screen -
so i'm working on opengl project in c++ , i'm running weird issue after creating glfwwindow , drawing it, area i'm drawing in encompasses bottom left quarter of screen. example if screen dimensions 640x480, , drew 40x40 square @ (600, 440) shows here, instead of in top right corner expect:
if move square area that's not within 640x480 parameter gets cut off, below:
i'll post code main.cpp below:
#define frame_cap 5000.0; #include <iostream> #include <gl/glew.h> #include <glfw/glfw3.h> #include "inputhandler.h" #include "game.h" using namespace std; void gameloop(glfwwindow *window){ inputhandler input = inputhandler(window); game game = game(input); //double frametime = 1.0 / frame_cap; while(!glfwwindowshouldclose(window)){ glint windowwidth, windowheight; glfwgetwindowsize(window, &windowwidth, &windowheight); glmatrixmode(gl_projection); glloadidentity(); glortho(0.0, windowwidth, 0.0, windowheight, -1.0, 1.0); glmatrixmode(gl_modelview); glloadidentity(); glviewport(0, 0, windowwidth, windowheight); game.render(); game.handleinput(); game.update(); glfwswapbuffers(window); glfwpollevents(); } } int main(int argc, const char * argv[]){ glfwwindow *window; if(!glfwinit()){ return -1; } window = glfwcreatewindow(640.0, 480.0, "opengl base project", null, null); if(!window){ glfwterminate(); exit(exit_failure); } glewinit(); glfwmakecontextcurrent(window); gameloop(window); glfwterminate(); exit(exit_success); }
i'm not sure why happening, if have ideas let me know, thank you!
for of me bump problem, need pass frame buffer size glviewport call, this:
glfwwindow * window = application::getinstance().currentwindow; glfwgetframebuffersize(window, &framebufferwidth, &framebufferheight); glviewport(0, 0, framebufferwidth, framebufferheight);
in devices (mainly apple retina displays), pixel dimensions don't match viewport dimensions 1:1. check here glfw documentation.
Comments
Post a Comment