2017-11-08 33 views
0

私はOpenGLを使って+ +記号を描画しています。私の画面は1920x1080の解像度を持っていますが、残念ながら私の描画方法( "glBegin(GL_LINES)")は1080x1080の四角形でのみ動作します。 x> screen_heightではすべてが途切れる。しかし、私はまだ1920x1080の全面に(Glutを使って)テキストを見つけることができます。あなたは設定が間違っているのを見つけるのを助けてくれますか?非正方形の画面上のOpenGL描画線

コードスニペットを添付しました。私は '+'記号の描画に使われたものだけを含んでいたので、これはコンパイルできません。

非常に高く評価されています。前もって感謝します。

// Libraries needed for OpenGL and strings 
#include <GL/glut.h> 
#include <GLFW/glfw3.h> 

// header file required for this cpp file 
#include "window2.hxx" 

int main(int argc, char *argv[]) 
{ 
// Start GLFW as main OpenGL frontend 
GLFWwindow* window; 

if(!glfwInit()) 
{ 
    fprintf(stderr, "Failed to initialize GLFW\n"); 
    exit(EXIT_FAILURE); 
} 

// Later upstream GLut is used for text rendering: thus also initialize GLUT (freeglut3) 
glutInit(&argc, argv); 

// check the resolution of the monitor and pass it to the create window function 
const GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor()); 
screen_width = mode->width; 
screen_height = mode->height; 
window = glfwCreateWindow(screen_width , screen_height, "LearnOpenGL", glfwGetPrimaryMonitor(), NULL); 


if (!window) 
{ 
    fprintf(stderr, "Failed to open GLFW window\n"); 
    glfwTerminate(); 
    exit(EXIT_FAILURE); 
} 


glfwMakeContextCurrent(window); 
glfwSwapInterval(1); 

// set up view 
glViewport(0, 0, screen_height, screen_width); 
glMatrixMode(GL_PROJECTION); 
glLoadIdentity(); 

// see https://www.opengl.org/sdk/docs/man2/xhtml/glOrtho.xml 
glOrtho(0.0,screen_height,0.0,screen_width,0.0,1.0); // this creates a canvas for 2D drawing on 

x_1 = 500; 
y_1 = 100; 

while(!glfwWindowShouldClose(window)) { 

    // Draw gears 
    render_loop(); 

    // Swap buffers 
    glfwSwapBuffers(window); 
    glfwPollEvents(); 

} // glfw while loop 
} 


//OpenGL Draw function 
void render_loop() 
{ 

// white background 
glClearColor (1.0f, 1.0f, 1.0f, 1.0f); 
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
glPointSize(10); 
glLineWidth(1); 

// push matrix 
glPushMatrix(); 

glColor3f(0.0, 0.0, 1.0); 
glBegin(GL_LINES); 
glVertex2i(x_1-10,y_1); 
glVertex2i(x_1+10,y_1); 
glVertex2i(x_1,y_1-10); 
glVertex2i(x_1,y_1+10); 
glEnd(); 

// pop matrix 
glPopMatrix(); 
} 

答えて

3

私はあなたの寸法ラウンド間違った方法を持っていると思う:

// set up view 
glViewport(0, 0, screen_height, screen_width); 
... 
glOrtho(0.0,screen_height,0.0,screen_width,0.0,1.0); 

は今、魔法のように

glViewport(0, 0, screen_width, screen_height); 
... 
glOrtho(0.0,screen_width,0.0,screen_height,0.0,1.0); 
+0

作品をお試しください。 glViewportエラーに気付かなかったため、問題を解決しようとするglOrthoを台無しにしました。ご協力いただきありがとうございます。 – Simon

+0

問題ありません、喜んで助けてください! –

関連する問題