|
glFlush(); 를 초기화 때 한번만 하고 RenderScene() 함수에서는 삭제하여 보세요....
압9정 님이 쓰신 글 :
: 안녕하세요^^ OpenGL을 막 시작한 초보입니다.ㅎㅎ
:
: 제가 구글에서 OpenGL을 사용하기 전에 기본적으로 해줘야하는 소스를 받았습니다.
:
: 근데 화면이 계속 검은색 흰색으로 거의 0.001초 주기로 깜빡 깜빡 거리기만 해요.ㄷ
:
: 이게 맞는건지...
:
: 그래서 테스트를 해볼려고 맽 밑에있는 예제소스를 버튼 이벤트로 실행시켜 봤는데요.
:
: 걍 계속 깜빡거림ㄷㄷ
:
: 뭐가 잘못된건가요??
:
: 예제소스만이라도 맞는건지 알려주세요.ㅠㅠ
:
: /*---------------------------------------------------------------------------
: 헤더
: ---------------------------------------------------------------------------*/
: #include <vcl\vcl.h>
: #include <Classes.hpp>
: #include <Controls.hpp>
: #include <StdCtrls.hpp>
: //---------------------------------------------------------------------------
:
: #ifndef OpenGL4cppH
: #define OpenGL4cppH
: //---------------------------------------------------------------------------
: #include <Classes.hpp>
: #include <Controls.hpp>
: #include <StdCtrls.hpp>
: #include <Forms.hpp>
: #include <gl/gl.h>
: #include <gl/glu.h>
:
: #define GL_PI 3.1415f
: //---------------------------------------------------------------------------
: class TMain : public TForm
: {
: __published: // IDE-managed Components
: void __fastcall FormCreate(TObject *Sender);
: void __fastcall FormDestroy(TObject *Sender);
: void __fastcall FormResize(TObject *Sender);
: private: // User declarations
: HDC hdc;
: HGLRC hrc;
: int PixelFormat;
: public: // User declarations
: __fastcall TMain(TComponent* Owner);
:
: void __fastcall IdleLoop(TObject*, bool&);
: void __fastcall RenderGLScene();
: void __fastcall SetupRC();
: void __fastcall SetPixelFormatDescriptor();
: };
: //---------------------------------------------------------------------------
: extern PACKAGE TMain *Main;
: //---------------------------------------------------------------------------
: #endif
:
:
:
: /*---------------------------------------------------------------------------
: 소스 파일
: ---------------------------------------------------------------------------*/
: __fastcall TMain::TMain(TComponent* Owner)
: : TForm(Owner)
: {
: Application->OnIdle = IdleLoop;
: // _control87(MCW_EM, MCW_EM);
: }
: //---------------------------------------------------------------------------
: void __fastcall TMain::IdleLoop(TObject*, bool& done)
: {
: done = false;
: RenderGLScene();
: SwapBuffers(hdc);
: }
: //---------------------------------------------------------------------------
: void __fastcall TMain::RenderGLScene()
: {
: //Place your OpenGL drawing code here
: }
: //---------------------------------------------------------------------------
: void __fastcall TMain::FormCreate(TObject *Sender)
: {
: hdc = GetDC(Handle);
: SetPixelFormatDescriptor();
: hrc = wglCreateContext(hdc);
: wglMakeCurrent(hdc, hrc);
: SetupRC();
: }
: //---------------------------------------------------------------------------
: void __fastcall TMain::FormDestroy(TObject *Sender)
: {
: // ReleaseDC(Handle, hdc);
: wglMakeCurrent(hdc, NULL);
: wglDeleteContext(hrc);
: }
: //---------------------------------------------------------------------------
: void __fastcall TMain::SetPixelFormatDescriptor()
: {
: PIXELFORMATDESCRIPTOR pfd = {
: sizeof(PIXELFORMATDESCRIPTOR),
: 1,
: PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
: PFD_TYPE_RGBA,
: 24,
: 0,0,0,0,0,0,
: 0,0,
: 0,0,0,0,0,
: 32,
: 0,
: 0,
: PFD_MAIN_PLANE,
: 0,
: 0,0,0
: };
: PixelFormat = ChoosePixelFormat(hdc, &pfd);
: SetPixelFormat(hdc, PixelFormat, &pfd);
: }
: //---------------------------------------------------------------------------
: void __fastcall TMain::FormResize(TObject *Sender)
: {
: GLfloat nRange = 200.0f;
: glViewport(0, 0, ClientWidth, ClientHeight);
: glMatrixMode(GL_PROJECTION);
: glLoadIdentity();
:
: if (ClientWidth <= ClientHeight)
: glOrtho(-nRange, nRange, -nRange*ClientHeight/ClientWidth,
: nRange*ClientHeight/ClientWidth, -nRange, nRange);
: else
: glOrtho(-nRange*ClientWidth/ClientHeight, nRange*ClientWidth/ClientHeight,
: -nRange, nRange, -nRange, nRange);
:
: glMatrixMode(GL_MODELVIEW);
: glLoadIdentity();
: }
: //---------------------------------------------------------------------------
: void __fastcall TMain::SetupRC()
: {
: glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
: glClear(GL_COLOR_BUFFER_BIT);
: glFlush();
: }
: //---------------------------------------------------------------------------
:
: /*---------------------------------------------------------------------------
: 예제 소스
: ---------------------------------------------------------------------------*/
: void __fastcall TMain::RenderScene()
: {
: GLfloat x,y,z,angle;
: glClear(GL_COLOR_BUFFER_BIT);
: glPushMatrix();
: glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
: glRotatef(90.0f, 0.0f, 1.0f, 0.0f);
: glBegin(GL_LINE_STRIP);
: z = -20.0f;
: for(angle = 0.0f; angle <= (2.0f * GL_PI) * 3.0f; angle += 0.1f)
: {
: x = 20.0f*sin(angle);
: y = 20.0f*cos(angle);
: glVertex3f(x, y, z);
: z += 0.5f;
: }
: glEnd();
: glPopMatrix();
: glFlush();
: }
: //---------------------------------------------------------------------------
|