Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: BCB and OpenGL...

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2006
    Location
    Bulgaria
    Posts
    18

    BCB and OpenGL...

    Hi.. I'm trying to create an OpenGL App. with Borland C++Builder 6.0. As far as I read I get to these:

    Unit1.cpp
    Code :
     #include <vcl.h>
    #pragma hdrstop
     
    #include "Unit1.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm1 *Form1;
    //---------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner)
    {
            Application->OnIdle = IdleLoop;
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::IdleLoop(TObject*, bool&amp; done)
    {
         RenderGLScene();
         SwapBuffers(hdc);
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::RenderGLScene()
    {
            glRectf(-5.0, 5.0, 5.0, -5.0);
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::FormCreate(TObject *Sender)
    {
        hdc = GetDC(Handle);
        SetPixelFormatDescriptor();
        hrc = wglCreateContext(hdc);
        wglMakeCurrent(hdc, hrc);
        SetupRC();
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::SetupRC()
    {
        glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT);
        glFlush();
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::FormDestroy(TObject *Sender)
    {
        ReleaseDC(Handle,hdc);
        wglMakeCurrent(NULL, NULL);
        wglDeleteContext(hrc);
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::SetPixelFormatDescriptor()
    {
            PIXELFORMATDESCRIPTOR pfd;
            ZeroMemory( &amp;pfd, sizeof( pfd ) );
            pfd.nSize = sizeof( pfd );
            pfd.nVersion = 1;
            pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL |
                  PFD_DOUBLEBUFFER;
            pfd.iPixelType = PFD_TYPE_RGBA;
            pfd.cColorBits = 24;
            pfd.cDepthBits = 16;
            pfd.iLayerType = PFD_MAIN_PLANE;
            int iFormat = ChoosePixelFormat( hdc, &amp;pfd );
            SetPixelFormat( hdc, iFormat, &amp;pfd );
    }
    Unit1.h
    Code :
     #include <Classes.hpp>
    #include <Controls.hpp>
    #include <StdCtrls.hpp>
    #include <Forms.hpp>
    #include <gl/gl.h>
    #include <gl/glu.h>
    //---------------------------------------------------------------------------
    class TForm1 : public TForm
    {
    __published:
        void __fastcall FormCreate(TObject *Sender);
        void __fastcall FormDestroy(TObject *Sender);
    private:
        HDC hdc;
        HGLRC hrc;
        int PixelFormat;
    public:
        __fastcall TForm1(TComponent* Owner);
        void __fastcall IdleLoop(TObject*, bool&amp;);
        void __fastcall RenderGLScene();
        void __fastcall SetPixelFormatDescriptor();
        void __fastcall SetupRC();
    };
    //---------------------------------------------------------------------------
    extern PACKAGE TForm1 *Form1;
    but only the window appears.. not the OpenGL and the rect it has to draw.. can anyone help me solv the problem.. Thanks beforehand

  2. #2
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,453

    Re: BCB and OpenGL...

    What's the result? A white window? Then it might just work.

    With the default transformation matrix setup OpenGL shows the contents of the unit cube range [-1.0, +1.0] in all three axes.

    Your clear color is white and the default color is white as well and your rect is too big.

    Try to replace the functions with the following code:
    glClearColor(0.0f, 0.0f, 0.5f, 0.0f); // dark blue
    and the TForm1::RenderGLScene() should contain
    glClear(GL_COLOR_BUFFER_BIT); // Belongs into the redraw function
    glColor3f(1.0f, 0.0f, 0.0f); // red
    glRectf(-0.5f, -0.5f, 0.5f, 0.5f);

    That should render a bright red rectangle in the middle of a dark blue background.

  3. #3
    Junior Member Newbie
    Join Date
    Oct 2006
    Location
    Bulgaria
    Posts
    18

    Re: BCB and OpenGL...

    just the same result... The window is not blue or white.. it's just with it default colour( foggy white )....

  4. #4
    Guest

    Re: BCB and OpenGL...

    Can you post your code to reflect the suggested modifications?

    Incidentally, you should be checking for errors/failure during the initialization process. Those function calls (wgl/PFD related) are not guaranteed to succeed. Please check the return values to be sure all is well.

  5. #5
    Intern Contributor uruk's Avatar
    Join Date
    Dec 2004
    Location
    acasa :) sau la munca :(
    Posts
    66

    Re: BCB and OpenGL...

    Add in the FormCreate function, before you call SetupRC(), the lines:
    Code :
    glViewport(0,0,ClientWidth,ClientHeight);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0.0,(float)ClientWidth,0.0,(float)ClientHeight,-100.0,100.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    Stat rosa pristina nomine, nomina nuda tenemus.

  6. #6
    Guest

    Re: BCB and OpenGL...

    Did you try running the sample OpenGL demo that comes with the C++ Builder installation in the Samples directory?

  7. #7
    Guest

    Re: BCB and OpenGL...

    the BCB example works perfectly and fits.. 10x

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •