C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[69043] OpenGL 초기화??
압9정 [] 1863 읽음    2013-01-24 13:39
안녕하세요^^ 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();
}
//---------------------------------------------------------------------------

+ -

관련 글 리스트
69043 OpenGL 초기화?? 압9정 1863 2013/01/24
69044     Re:OpenGL 초기화?? 송신영 2072 2013/01/24
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.