PDA

View Full Version : OpenGL, and C++ Builder 4.0



10-12-2001, 03:16 PM
I am trying to get Open GL graphics to display in a TPaintBox object. I cannot get anything to display. I am new at this, and so if a TPaintBox component is not supposed to be used for this purpose, please let me know what kind of component I am supposed to use. I have posted my code below, which should draw a white rectangle on a blackbackground inside the picture box. Any suggestions would be greatly appreciated.

void __fastcall TMain_Form::PaintBox1Paint(TObject *Sender)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glOrtho(0.0, 1.0, 0.0, 1.0, 0.0, 1.0);
glBegin(GL_POLYGON);
glVertex2f(0.25, 0.25);
glVertex2f(0.75, 0.25);
glVertex2f(0.75, 0.75);
glVertex2f(0.25, 0.75);
glEnd();
glFlush();
}

Thanks,
Christopher Messick

Stonemaster
10-13-2001, 12:59 AM
I don't use C++ Builder anymore because I only had problems when using OpenGL. VC++ is better for such things. But I can remember a component that lets you draw OpenGL in it. It can be found here: http://www.hellix.com/Products/TOpenGL.asp. It's derived from TPanel and initializes OpenGL for you so you have only to handle the window messages and draw something. Your code didn't work because you have to init OpenGL, create a rendering context, set the pixel format etc., before you can use the drawing commands. Hope that helps!

Bye,
André.
-----
http://www.steinsoft.net

[This message has been edited by Stonemaster (edited 10-13-2001).]

MButchers
10-13-2001, 01:53 AM
Hi there,

use a TPanel instead and get the HDC with
HDC dc = GetDC(Panel1->Handle);

Hope it helps


Mark