시뮬레이트 된 "tv 정적"창이있는 프로그램을 작성하려고합니다. 나는 주로 작업하지만 창이 그리드 선을 확장 할 때 사용합니다. 이게 내 첫 OpenGL (glut) 프로그램 인 이유는 무엇일까. 어떤 제안? 사전에 감사 OpenGL (glut) - 픽셀 배치 정밀도를 높이십시오.
#include <GLUT/glut.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
void display(void){
/* clear window */
glClear(GL_COLOR_BUFFER_BIT);
int maxy = glutGet(GLUT_WINDOW_HEIGHT);
int maxx = glutGet(GLUT_WINDOW_WIDTH);
glBegin(GL_POINTS);
for (int y = 0; y <= maxy; ++y) {
for (int x = 0; x <= maxx; ++x) {
glColor3d(rand()/(float) RAND_MAX,rand()/(float) RAND_MAX,rand()/(float) RAND_MAX);
glVertex2i(x, y);
}
}
glEnd();
/* flush GL buffers */
glFlush();
}
void init(){
/* set clear color to black */
glClearColor (0.0, 0.0, 0.0, 1.0);
/* set fill color to white */
glColor3f(1.0, 1.0, 1.0);
/* set up standard orthogonal view with clipping */
/* box as cube of side 2 centered at origin */
/* This is default view and these statement could be removed */
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
glOrtho(0, glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT), 0, 0, 1);
glDisable(GL_DEPTH_TEST);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity();
}
int main(int argc, char** argv){
srand(time(NULL));
/* Initialize mode and open a window in upper left corner of screen */
/* Window title is name of program (arg[0]) */
glutInit(&argc,argv);
//You can try the following to set the size and position of the window
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow("simple");
glutDisplayFunc(display);
init();
glutIdleFunc(display);
glutMainLoop();
}
편집 : 나는 glRecti
를 사용하여 라인을 제거 할 수 있습니다; 그러나 창이 커질수록 픽셀이 커집니다.
:이 트릭을 할해야합니다 귀하의 경우에는
– romejoe