PDA

View Full Version : access violation



06-02-2000, 04:48 AM
i been trying to run the c++ builder example
from the bits site and everytime i try to compile the following code i get an access violation error ..#include <vcl\vcl.h>
#pragma hdrstop

#include "GLSkeleton.h"
//---------------------------------------------------------------------------
#pragma resource "*.dfm"

TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
Application->OnIdle = IdleLoop;
size = 50.0f;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::IdleLoop(TObject*, bool& done)
{
done = false;
RenderGLScene();
SwapBuffers(hdc);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RenderGLScene()
{
DrawObjects();
}
//---------------------------------------------------------------------------
void __fastcall TForm1: http://www.opengl.org/discussion_boards/ubb/biggrin.gifrawObjects()
{
//Insert OpenGL drawing code here
glBegin(GL_TRIANGLE_STRIP);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(-50.0f, 0.0f, 0.0f);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f(0.0f, 100.0f, 0.0f);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex3f(50.0f, 0.0f, 0.0f);
glEnd();
glFlush();

}
//---------------------------------------------------------------------------
void __fastcall TForm1::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,
24,
0,
0,
PFD_MAIN_PLANE,
0,
0,0,
};
PixelFormat = ChoosePixelFormat(hdc, &pfd);
SetPixelFormat(hdc, PixelFormat, &pfd);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormResize(TObject *Sender)
{
GLfloat nRange = 500.0f;

// Prevent a divide by zero
if(h == 0)
h = 1;

// Set Viewport to window dimensions
glViewport(0, 0, w, h);

// Reset projection matrix stack
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

// Establish clipping volume (left, right, bottom, top, near, far)
if (w <= h)
glOrtho (-nRange, nRange, -nRange*h/w, nRange*h/w, -nRange, nRange);
else
glOrtho (-nRange*w/h, nRange*w/h, -nRange, nRange, -nRange, nRange);

// Reset Model view matrix stack
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormPaint(TObject *Sender)
{
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
DrawObjects();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormDestroy(TObject *Sender)
{
wglMakeCurrent(NULL, NULL);
wglDeleteContext(hrc);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormActivate(TObject *Sender)
{
hdc = GetDC(Handle);
SetPixelFormatDescriptor();
hrc = wglCreateContext(hdc);
if(hrc == NULL)
ShowMessage(":-)~ hrc == NULL");
if(wglMakeCurrent(hdc, hrc) == false)
ShowMessage("Could not MakeCurrent");
w = ClientWidth;
h = ClientHeight;
}
//---------------------------------------------------------------------------

i'm using v3 3k and amd 350. can somebody please help?