OpenGL-如何绘制完整的窗口矩形
OpenGL - how to draw a full window rectangle
实际上,我要做的是显示一个与我创建的窗口相同的图像。但是我发现带有图像纹理的矩形将略微放大,以使图像的边缘看不见。
因此,我进行了以下实验:对于我的窗口尺寸500x500,我先绘制一个尺寸为500x500的矩形,并首先绘制第二个矩形,并用(500-2) *(500-2)用黑色绘制。我得到的只是一个黑色窗口。通过将代码中D的值增加到8,红线在左/右和底部显示,顶部显示直到d = 33。
我认为这是因为深度或投影,但我不知道如何修复它。有没有建议?
以下是我的示例代码:
#include <GL/glut.h> /* glut.h includes gl.h and glu.h*/
void rectangle(float x, float y, float x1, double y1, float r, float g, float b)
{
glColor3f(r, g, b);
glBegin(GL_QUADS);
glVertex2f(x, y);
glVertex2f(x, y1);
glVertex2f(x1, y1);
glVertex2f(x1, y);
glEnd();
}
void display()
{
/* clear window */
glClear(GL_COLOR_BUFFER_BIT);
int d = 33;
// draw rectangle in red
rectangle(d, d, 500 - d, 500 - d, 1, 0, 0);
// draw rectangle in black
rectangle(d + 1, d + 1, 500 - d - 1, 500 - d - 1, 0, 0, 0);
/* flush GL buffers */
glFlush();
}
void init()
{
/* set clear color to black */
glClearColor(0.0, 0.0, 0.0, 0.0);
/* set fill color to white */
/* set up standard orthogonal view with clipping */
/* box as cube of side 2 centered at origin */
/* This is default view and these statements could be removed */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, 500, 0, 500);
}
int main(int argc, char** argv)
{
/* Initialize mode and open a window in upper left corner of
/* screen */
/* Window title is name of program (arg[0]) */
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500, 500);
glutInitWindowPosition(0, 0);
glutCreateWindow("simple");
glutDisplayFunc(display);
init();
glutMainLoop();
}
我不确定这是否是过多的错误,但是我发现偏移值仅等于窗口边框的厚度。也就是说,对于左/右/底部边缘,偏移= 9像素,顶部的偏移= 32。
看起来,虽然Glutinitwindowsize(500,500)用500x500初始化窗口的黑色区域,但它还假定包含边界为500x500的整个窗口大小。然后,当我绘制500x500的矩形时,它将拉伸矩形以适合创建窗口的轮廓,但不适合内部黑色区域。
我的解决方法是将Gluortho2D设置为使用(-window_left,500 window_right,0 -Windows_bottom,500 window_top)的区域,但仍在(0,0,500,500)绘制矩形:
):gluOrtho2D(0 - 9, 500 + 9, 0 - 9, 500 + 40); // 40 is an empirical value for showing the red rectangle completely
相关文章:
- QuadTree只在窗口的右上角绘制
- SFML 文本未绘制在窗口上
- GDI 绘制到外部窗口 (C++)
- 使用标准窗口与wxWidgets一起绘制?
- 如何在SDL2窗口上使用Cairo绘制一条白色直线
- 为什么在GLFW窗口中没有用这个代码在我的屏幕上绘制立方体
- 如何在窗口外绘制图形(OpenGL GLFW)
- 在放大镜窗口上绘制(放大 API)
- 在窗口上绘制 PNG 图像 - C++ SDL 2.0
- 在第三方应用程序的窗口顶部绘制
- 在没有项目的情况下使用 Dev c++ 在窗口中绘制文本
- gtkmm 2.4 开罗时钟示例在修改为在 HBox 内部而不是主窗口内绘制时不起作用
- 使用SFML在另一个类的主窗口中绘制
- WinAPI 窗口在绘制后不刷新
- 在C++窗口中绘制图形
- 用窗口线绘制正方形
- MFC在最大化窗口处绘制新窗口
- 在窗口中绘制之前是否有必要使更新区域无效?
- 是否可以在另一个窗口中绘制(使用 Opencv/ffmpeg
- 如何在两个不同的borland builder窗口中绘制相同的opengl图