0
나는 '+'기호를 그릴 때 OpenGL을 C++로 사용하고 있습니다. 내 화면의 해상도는 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();
}
작품을보십시오. glViewport 오류를 알지 못했고, 따라서 문제를 해결하기 위해 glOrtho를 엉망으로 만들었습니다. 도와 주셔서 대단히 감사합니다. – Simon
문제 없습니다. 기꺼이 도와주세요! –