2011-02-25 3 views
0

시뮬레이트 된 "tv 정적"창이있는 프로그램을 작성하려고합니다. 나는 주로 작업하지만 창이 그리드 선을 확장 할 때 사용합니다. 이게 내 첫 OpenGL (glut) 프로그램 인 이유는 무엇일까. 어떤 제안? 사전에 감사 enter image description hereOpenGL (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를 사용하여 라인을 제거 할 수 있습니다; 그러나 창이 커질수록 픽셀이 커집니다.

+0

:이 트릭을 할해야합니다 귀하의 경우에는

romejoe

답변

2

귀하의 화면 크기는 width*height이지만 실제는 (width+1)*(height+1)입니다. 또한 경계 픽셀은 경계선 오른쪽에 그려 지므로 볼 수 있을지 잘 모르겠습니다.

솔루션 :

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); 
     glVertex2f(x+0.5f, y+0.5f); 
    } 
} 

공지 루프 조건과는 glVertex 호출 유형의 변화.

1

창 크기를 조정할 때 glut의 내부 아이디어가 업데이트되지 않는 것 같습니다. 창 크기 조정 핸들러가 필요할 수 있습니다.

3

사용

void glutReshapeFunc(void (*func)(int width, int height)); 

때 창 크기 변경을 투사, glOrtho를 재설정. 나는 공간 (0.3 씩 증가)을 작성하기 위해 KVARK의 코드를 수정 결국

void resize(int width,int height) 
{ 
    glOrtho(0, width, height, 0, 0, 1); 
} 

int main(int argc, char** argv){ 
    //... 
    glutReshapeFunc(resize); 

    glutDisplayFunc(display); 
    init(); 
    glutIdleFunc(display); 
    glutMainLoop(); 
}