<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[form bei OpenGL öffnen]]></title><description><![CDATA[<p>hi</p>
<p>hab folgenes problem hoffe mir kann da einer weiterhelfen...</p>
<p>ich habe ein openGL projekt von einem touturial übernommen (quelltext folgt)<br />
und möchte damit dann eine 3d landschaft realisieren die zu durchlaufen ist...<br />
das ganze ist erstellt in dem borland bilder 6.0...<br />
nun möchte ich das mit der taste &quot;i&quot; ein form geöfnet wird wo dann z.b. ein inventar zu sehen ist etc...<br />
das problem ist das wenn ich das form1 mit &quot;ShowModal()&quot; aufrufen will bekomm ich immer die fehlermeldung:<br />
&quot;Im Projekt test.exe ist eine Exception der Klasse EAccessViolation aufgetreten. Meldung: 'Zugriffsverletzung bei Adresse 004022EE. Lesen von Adresse 00000000'. Prozeß wurde angehalten. Mit Einzelne Anweisung oder Start fortsetzen.&quot;</p>
<p>der debuger hält an der stelle Form1-&gt;ShowModal(); an hab in dem Form1 bislang noch nichts drin...</p>
<p>kann mir jemand helfen und mir sagen was ich da falsch gemacht hab oder wie ich ein form in das projekt integrieren kann???</p>
<p>PS: der code von dem toturial selbst also der OpenGL code funktioniert eben nur das aufrufen des forms nicht....</p>
<pre><code>//---------------------------------------------------------------------------

#include &lt;vcl.h&gt;
#include &lt;windows.h&gt;    // Header file for windows
#include &lt;math.h&gt;	// Math library header file
#include &lt;stdio.h&gt;	// Header file for standard Input/Output
#include &lt;gl\gl.h&gt;      // Header file for the OpenGL32 library
#include &lt;gl\glu.h&gt;     // Header file for the GLu32 library
#include &lt;gl\glaux.h&gt;   // Header file for the GLaux library
#include &quot;Unit1.h&quot;
#pragma hdrstop

//---------------------------------------------------------------------------
#pragma argsused

HGLRC hRC = NULL;               // Permanent rendering context
HDC hDC = NULL;                 // Private GDI device context
HWND hWnd = NULL;               // Holds our window handle
HINSTANCE hInstance = NULL;     // Holds the instance of the application

bool keys[256];                 // Array used for the keyboard routine
bool active = true;             // Window active flag set to TRUE by default
bool fullscreen = true;         // Fullscreen flag set to fullscreen mode by default

bool blend;			// Blending ON/OFF
bool bp;			// B pressed?
bool fp;			// F pressed?

const float piover180 = 0.0174532925f;
float heading;
float xpos;
float zpos;

GLfloat	yrot;                   // Y Rotation
GLfloat walkbias = 0;
GLfloat walkbiasangle = 0;
GLfloat lookupdown = 0.0f;
GLfloat	z = 0.0f;               // Depth into the screen

GLuint filter;			// Which filter to use
GLuint texture[3];		// Storage for 3 textures

typedef struct tagVERTEX
{
	float x, y, z;
	float u, v;
} VERTEX;

typedef struct tagTRIANGLE
{
	VERTEX vertex[3];
} TRIANGLE;

typedef struct tagSECTOR
{
	int numtriangles;
	TRIANGLE* triangle;
} SECTOR;

SECTOR sector1;         // Our model goes here:

LRESULT	CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);   // Declaration for WndProc

void readstr(FILE *f,char *string)
{
	do
	{
		fgets(string, 255, f);
	} while ((string[0] == '/') || (string[0] == '\n'));
	return;
}

void SetupWorld()
{
	float x, y, z, u, v;
	int numtriangles;
	FILE *filein;
	char oneline[255];
	filein = fopen(&quot;data/world.txt&quot;, &quot;rt&quot;);	        // File to load world data from

	readstr(filein,oneline);
	sscanf(oneline, &quot;NUMPOLLIES %d\n&quot;, &amp;numtriangles);

	sector1.triangle = new TRIANGLE[numtriangles];
	sector1.numtriangles = numtriangles;
	for (int loop = 0; loop &lt; numtriangles; loop++)
	{
		for (int vert = 0; vert &lt; 3; vert++)
		{
			readstr(filein,oneline);
			sscanf(oneline, &quot;%f %f %f %f %f&quot;, &amp;x, &amp;y, &amp;z, &amp;u, &amp;v);
			sector1.triangle[loop].vertex[vert].x = x;
			sector1.triangle[loop].vertex[vert].y = y;
			sector1.triangle[loop].vertex[vert].z = z;
			sector1.triangle[loop].vertex[vert].u = u;
			sector1.triangle[loop].vertex[vert].v = v;
		}
	}
	fclose(filein);
	return;
}

AUX_RGBImageRec *LoadBMP(char *Filename)                // Loads a bitmap image
{
        FILE *File=NULL;                                // File handle

        if (!Filename)                                  // Make sure a filename was given
        {
                return NULL;                            // If not return NULL
        }

        File=fopen(Filename,&quot;r&quot;);                       // Check to see if the file exists

        if (File)                                       // Does the file exist?
        {
                fclose(File);                           // Close the handle
                return auxDIBImageLoad(Filename);       // Load the bitmap and return a pointer
        }
        return NULL;                                    // If load failed return NULL
}

int LoadGLTextures()                                    // Load bitmaps and convert to textures
{
        int Status = false;                             // Status indicator

        AUX_RGBImageRec *TextureImage[1];               // Create storage space for the texture

        memset(TextureImage,0,sizeof(void *)*1);        // Set the pointer to NULL

        // Load the bitmap, check for errors, if bitmap's not found quit
        if (TextureImage[0]=LoadBMP(&quot;Data/Mud.bmp&quot;))
        {
                Status = true;                          // Set the status to TRUE

                glGenTextures(3, &amp;texture[0]);          // Create three textures

				// Create nearest filtered texture
				glBindTexture(GL_TEXTURE_2D, texture[0]);
				glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
				glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
				glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]-&gt;sizeX, TextureImage[0]-&gt;sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]-&gt;data);

                // Create linear filtered texture
                glBindTexture(GL_TEXTURE_2D, texture[1]);
                glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
                glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
                glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]-&gt;sizeX, TextureImage[0]-&gt;sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]-&gt;data);

				// Create mipmapped texture
				glBindTexture(GL_TEXTURE_2D, texture[2]);
				glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
				glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
				gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]-&gt;sizeX, TextureImage[0]-&gt;sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]-&gt;data);
        }
        if (TextureImage[0])    // If texture exists
        {
                if (TextureImage[0]-&gt;data)      // If texture image exists
                {
                        free(TextureImage[0]-&gt;data);    // Free the texture image memory
                }

                free(TextureImage[0]);          // Free the image structure
        }

        return Status;          // Return the status
}

GLvoid ReSizeGLScene(GLsizei width, GLsizei height)     // Resize and initialize the GL window
{
        if (height == 0)                        // Prevent a divide by zero by
        {
                height = 1;                     // Making height equal One
        }

        glViewport(0, 0, width, height);        // Reset the current viewport

        glMatrixMode(GL_PROJECTION);            // Select the projection matrix
	glLoadIdentity();                       // Reset the projection matrix

	// Calculate the aspect ratio of the window
	gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);

	glMatrixMode(GL_MODELVIEW);             // Select the modelview matrix
	glLoadIdentity();                       // Reset the modelview matrix
}

int InitGL(GLvoid)      // All setup for OpenGL goes here
{
	if (!LoadGLTextures())          // Jump to texture loading routine
	{
		return false;           // If texture didn't load return FALSE
	}

	glEnable(GL_TEXTURE_2D);	        // Enable texture mapping
	glBlendFunc(GL_SRC_ALPHA,GL_ONE);	// Set the blending function for translucency
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);	// This will clear the background color to black
	glClearDepth(1.0);			// Enables clearing of the depth buffer
	glDepthFunc(GL_LESS);			// The type of depth test to do
	glEnable(GL_DEPTH_TEST);		// Enables depth testing
	glShadeModel(GL_SMOOTH);		// Enables smooth color shading
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);	// Really nice perspective calculations

	SetupWorld();

	return TRUE;            // Initialization went OK
}

int DrawGLScene(GLvoid)         // Here's where we do all the drawing
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);     // Clear the screen and the depth buffer
	glLoadIdentity();					// Reset the view

	GLfloat x_m, y_m, z_m, u_m, v_m;
	GLfloat xtrans = -xpos;
	GLfloat ztrans = -zpos;
	GLfloat ytrans = -walkbias-0.25f;
	GLfloat sceneroty = 360.0f - yrot;

	int numtriangles;

	glRotatef(lookupdown,1.0f,0,0);
	glRotatef(sceneroty,0,1.0f,0);

	glTranslatef(xtrans, ytrans, ztrans);
	glBindTexture(GL_TEXTURE_2D, texture[filter]);

	numtriangles = sector1.numtriangles;

	// Process each triangle
	for (int loop_m = 0; loop_m &lt; numtriangles; loop_m++)
	{
		glBegin(GL_TRIANGLES);
			glNormal3f( 0.0f, 0.0f, 1.0f);
			x_m = sector1.triangle[loop_m].vertex[0].x;
			y_m = sector1.triangle[loop_m].vertex[0].y;
			z_m = sector1.triangle[loop_m].vertex[0].z;
			u_m = sector1.triangle[loop_m].vertex[0].u;
			v_m = sector1.triangle[loop_m].vertex[0].v;
			glTexCoord2f(u_m,v_m); glVertex3f(x_m,y_m,z_m);

			x_m = sector1.triangle[loop_m].vertex[1].x;
			y_m = sector1.triangle[loop_m].vertex[1].y;
			z_m = sector1.triangle[loop_m].vertex[1].z;
			u_m = sector1.triangle[loop_m].vertex[1].u;
			v_m = sector1.triangle[loop_m].vertex[1].v;
			glTexCoord2f(u_m,v_m); glVertex3f(x_m,y_m,z_m);

			x_m = sector1.triangle[loop_m].vertex[2].x;
			y_m = sector1.triangle[loop_m].vertex[2].y;
			z_m = sector1.triangle[loop_m].vertex[2].z;
			u_m = sector1.triangle[loop_m].vertex[2].u;
			v_m = sector1.triangle[loop_m].vertex[2].v;
			glTexCoord2f(u_m,v_m); glVertex3f(x_m,y_m,z_m);
		glEnd();
	}
	return true;            // Everything went OK
}

GLvoid KillGLWindow(GLvoid)     // Properly kill the window
{
	if (fullscreen)         // Are we in fullscreen mode?
	{
		ChangeDisplaySettings(NULL,0);  // If so switch back to the desktop
		ShowCursor(true);               // Show mouse pointer
	}

	if (hRC)        // Do we have a rendering context?
	{
		if (!wglMakeCurrent(NULL,NULL))         // Are we able to release the DC and RC contexts?
		{
			MessageBox(NULL,&quot;Release of DC and RC failed.&quot;,&quot;SHUTDOWN ERROR&quot;,MB_OK | MB_ICONINFORMATION);
		}

		if (!wglDeleteContext(hRC))             // Are we able to delete the RC?
		{
			MessageBox(NULL,&quot;Release rendering context failed.&quot;,&quot;SHUTDOWN ERROR&quot;,MB_OK | MB_ICONINFORMATION);
		}
		hRC = NULL;             // Set RC to NULL
	}

	if (hDC &amp;&amp; !ReleaseDC(hWnd,hDC))        // Are we able to release the DC
	{
		MessageBox(NULL,&quot;Release device context failed.&quot;,&quot;SHUTDOWN ERROR&quot;,MB_OK | MB_ICONINFORMATION);
		hDC = NULL;             // Set DC to NULL
	}

	if (hWnd &amp;&amp; !DestroyWindow(hWnd))       // Are we able to destroy the window?
	{
		MessageBox(NULL,&quot;Could not release hWnd.&quot;,&quot;SHUTDOWN ERROR&quot;,MB_OK | MB_ICONINFORMATION);
		hWnd = NULL;            // Set hWnd to NULL
	}

	if (!UnregisterClass(&quot;OpenGL&quot;,hInstance))       // Are we able to unregister class
	{
		MessageBox(NULL,&quot;Could not unregister class.&quot;,&quot;SHUTDOWN ERROR&quot;,MB_OK | MB_ICONINFORMATION);
		hInstance = NULL;       // Set hInstance to NULL
	}
}

/*	This Code Creates Our OpenGL Window.  Parameters Are:
 *	title			- Title To Appear At The Top Of The Window
 *	width			- Width Of The GL Window Or Fullscreen Mode
 *	height			- Height Of The GL Window Or Fullscreen Mode
 *	bits			- Number Of Bits To Use For Color (8/16/24/32)
 *	fullscreenflag	- Use Fullscreen Mode (TRUE) Or Windowed Mode (FALSE)*/

BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag)
{
	GLuint		PixelFormat;		// Holds the results after searching for a match
	WNDCLASS	wc;		        // Windows class structure
	DWORD		dwExStyle;              // Window extended style
	DWORD		dwStyle;                // Window style
	RECT		WindowRect;             // Grabs rctangle upper left / lower right values
	WindowRect.left = (long)0;              // Set left value to 0
	WindowRect.right = (long)width;		// Set right value to requested width
	WindowRect.top = (long)0;               // Set top value to 0
	WindowRect.bottom = (long)height;       // Set bottom value to requested height

	fullscreen = fullscreenflag;              // Set the global fullscreen flag

	hInstance               = GetModuleHandle(NULL);		// Grab an instance for our window
	wc.style                = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;   // Redraw on size, and own DC for window
	wc.lpfnWndProc          = (WNDPROC) WndProc;			// WndProc handles messages
	wc.cbClsExtra           = 0;					// No extra window data
	wc.cbWndExtra           = 0;					// No extra window data
	wc.hInstance            = hInstance;				// Set the Instance
	wc.hIcon                = LoadIcon(NULL, IDI_WINLOGO);		// Load the default icon
	wc.hCursor              = LoadCursor(NULL, IDC_ARROW);		// Load the arrow pointer
	wc.hbrBackground        = NULL;					// No background required for GL
	wc.lpszMenuName		= NULL;					// We don't want a menu
	wc.lpszClassName	= &quot;OpenGL&quot;;				// Set the class name

	if (!RegisterClass(&amp;wc))					// Attempt to register the window class
	{
		MessageBox(NULL,&quot;Failed To Register The Window Class.&quot;,&quot;ERROR&quot;,MB_OK|MB_ICONEXCLAMATION);

		return false;   // Return FALSE
	}

	if (fullscreen)         // Attempt fullscreen mode?
	{
		DEVMODE dmScreenSettings;                                       // Device mode
		memset(&amp;dmScreenSettings,0,sizeof(dmScreenSettings));	        // Makes sure memory's cleared
		dmScreenSettings.dmSize         = sizeof(dmScreenSettings);     // Size of the devmode structure
		dmScreenSettings.dmPelsWidth	= width;                        // Selected screen width
		dmScreenSettings.dmPelsHeight	= height;                       // Selected screen height
		dmScreenSettings.dmBitsPerPel	= bits;	                        // Selected bits per pixel
		dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;

		// Try to set selected mode and get results. NOTE: CDS_FULLSCREEN gets rid of start bar.
		if (ChangeDisplaySettings(&amp;dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)
		{
			// If the mode fails, offer two options. Quit or use windowed mode.
			if (MessageBox(NULL,&quot;The requested fullscreen mode is not supported by\nyour video card. Use windowed mode instead?&quot;,&quot;NeHe GL&quot;,MB_YESNO|MB_ICONEXCLAMATION)==IDYES)
			{
				fullscreen = false;       // Windowed mode selected. Fullscreen = FALSE
			}
			else
			{
				// Pop up a message box letting user know the program is closing.
				MessageBox(NULL,&quot;Program will now close.&quot;,&quot;ERROR&quot;,MB_OK|MB_ICONSTOP);
				return false;           // Return FALSE
			}
		}
	}

	if (fullscreen)                         // Are We Still In Fullscreen Mode?
	{
		dwExStyle = WS_EX_APPWINDOW;    // Window extended style
		dwStyle = WS_POPUP;		// Windows style
		ShowCursor(false);		// Hide mouse pointer
	}
	else
	{
		dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;           // Window extended style
		dwStyle=WS_OVERLAPPEDWINDOW;                            // Windows style
	}

	AdjustWindowRectEx(&amp;WindowRect, dwStyle, FALSE, dwExStyle);     // Adjust window to true requested size

	// Create the window
	if (!(hWnd = CreateWindowEx(dwExStyle,          // Extended Style For The Window
                &quot;OpenGL&quot;,				// Class name
		title,					// Window title
		dwStyle |				// Defined window style
		WS_CLIPSIBLINGS |			// Required window style
		WS_CLIPCHILDREN,			// Required window style
		0, 0,					// Window position
		WindowRect.right-WindowRect.left,	// Calculate window width
		WindowRect.bottom-WindowRect.top,	// Calculate window height
		NULL,					// No parent window
		NULL,					// No menu
		hInstance,				// Instance
		NULL)))					// Dont pass anything to WM_CREATE
	{
		KillGLWindow();                         // Reset the display
		MessageBox(NULL,&quot;Window Creation Error.&quot;,&quot;ERROR&quot;,MB_OK|MB_ICONEXCLAMATION);
		return false;                           // Return FALSE
	}

	static	PIXELFORMATDESCRIPTOR pfd =             // pfd tells windows how we want things to be
	{
		sizeof(PIXELFORMATDESCRIPTOR),          // Size of this pixel format descriptor
		1,					// Version number
		PFD_DRAW_TO_WINDOW |			// Format must support window
		PFD_SUPPORT_OPENGL |			// Format must support OpenGL
		PFD_DOUBLEBUFFER,			// Must support double buffering
		PFD_TYPE_RGBA,				// Request an RGBA format
		bits,					// Select our color depth
		0, 0, 0, 0, 0, 0,			// Color bits ignored
		0,					// No alpha buffer
		0,					// Shift bit ignored
		0,					// No accumulation buffer
		0, 0, 0, 0,				// Accumulation bits ignored
		16,					// 16Bit Z-Buffer (Depth buffer)
		0,					// No stencil buffer
		0,					// No auxiliary buffer
		PFD_MAIN_PLANE,				// Main drawing layer
		0,					// Reserved
		0, 0, 0					// Layer masks ignored
	};

	if (!(hDC=GetDC(hWnd)))         // Did we get a device context?
	{
		KillGLWindow();         // Reset the display
		MessageBox(NULL,&quot;Can't create a GL device context.&quot;,&quot;ERROR&quot;,MB_OK|MB_ICONEXCLAMATION);
		return false;           // Return FALSE
	}

	if (!(PixelFormat=ChoosePixelFormat(hDC,&amp;pfd)))	// Did windows find a matching pixel format?
	{
		KillGLWindow();         // Reset the display
		MessageBox(NULL,&quot;Can't find a suitable pixelformat.&quot;,&quot;ERROR&quot;,MB_OK|MB_ICONEXCLAMATION);
		return false;           // Return FALSE
	}

	if(!SetPixelFormat(hDC,PixelFormat,&amp;pfd))       // Are we able to set the pixel format?
	{
		KillGLWindow();         // Reset the display
		MessageBox(NULL,&quot;Can't set the pixelformat.&quot;,&quot;ERROR&quot;,MB_OK|MB_ICONEXCLAMATION);
		return false;           // Return FALSE
	}

	if (!(hRC=wglCreateContext(hDC)))               // Are we able to get a rendering context?
	{
		KillGLWindow();         // Reset the display
		MessageBox(NULL,&quot;Can't create a GL rendering context.&quot;,&quot;ERROR&quot;,MB_OK|MB_ICONEXCLAMATION);
		return false;           // Return FALSE
	}

	if(!wglMakeCurrent(hDC,hRC))    // Try to activate the rendering context
	{
		KillGLWindow();         // Reset the display
		MessageBox(NULL,&quot;Can't activate the GL rendering context.&quot;,&quot;ERROR&quot;,MB_OK|MB_ICONEXCLAMATION);
		return false;           // Return FALSE
	}

	ShowWindow(hWnd,SW_SHOW);       // Show the window
	SetForegroundWindow(hWnd);      // Slightly higher priority
	SetFocus(hWnd);                 // Sets keyboard focus to the window
	ReSizeGLScene(width, height);   // Set up our perspective GL screen

	if (!InitGL())                  // Initialize our newly created GL window
	{
		KillGLWindow();         // Reset the display
		MessageBox(NULL,&quot;Initialization failed.&quot;,&quot;ERROR&quot;,MB_OK|MB_ICONEXCLAMATION);
		return false;           // Return FALSE
	}

	return true;                    // Success
}

LRESULT CALLBACK WndProc(HWND hWnd,     // Handle for this window
                        UINT uMsg,      // Message for this window
			WPARAM wParam,  // Additional message information
			LPARAM lParam)  // Additional message information
{
	switch (uMsg)                           // Check for windows messages
	{
		case WM_ACTIVATE:               // Watch for window activate message
		{
			if (!HIWORD(wParam))    // Check minimization state
			{
				active = true;  // Program is active
			}
			else
			{
				active = false; // Program is no longer active
			}

			return 0;               // Return to the message loop
		}

		case WM_SYSCOMMAND:             // Intercept system commands
		{
			switch (wParam)         // Check system calls
			{
				case SC_SCREENSAVE:     // Screensaver trying to start?
				case SC_MONITORPOWER:	// Monitor trying to enter powersave?
				return 0;       // Prevent from happening
			}
			break;                  // Exit
		}

		case WM_CLOSE:                  // Did we receive a close message?
		{
			PostQuitMessage(0);     // Send a quit message
			return 0;               // Jump back
		}

		case WM_KEYDOWN:                // Is a key being held down?
		{
			keys[wParam] = true;    // If so, mark it as TRUE
			return 0;               // Jump back
		}

		case WM_KEYUP:                  // Has a key been released?
		{
			keys[wParam] = false;   // If so, mark it as FALSE
			return 0;               // Jump back
		}

		case WM_SIZE:                   // Resize the OpenGL window
		{
			ReSizeGLScene(LOWORD(lParam),HIWORD(lParam));  // LoWord = Width, HiWord = Height
			return 0;               // Jump back
		}
	}

	// Pass all unhandled messages to DefWindowProc
	return DefWindowProc(hWnd,uMsg,wParam,lParam);
}

WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
        MSG msg;                // Windows message structure
	bool done = false;      // Bool variable to exit loop

	// Ask the user which screen mode they prefer
	if (MessageBox(NULL,&quot;Would you like to run in fullscreen mode?&quot;, &quot;Start FullScreen?&quot;,MB_YESNO|MB_ICONQUESTION)==IDNO)
	{
		fullscreen = false;       // Windowed mode
	}

	// Create our OpenGL window
	if (!CreateGLWindow(&quot;Lionel Brits &amp; NeHe's 3D World Tutorial&quot;,640,480,16,fullscreen))
	{
		return 0;               // Quit if window was not created
	}

	while(!done)            // Loop that runs while done = FALSE
	{
		if (PeekMessage(&amp;msg,NULL,0,0,PM_REMOVE))	// Is there a message waiting?
		{
			if (msg.message == WM_QUIT)             // Have we received a quit message?
			{
				done = true;                    // If so done = TRUE
			}
			else                                    // If not, deal with window messages
			{
				TranslateMessage(&amp;msg);         // Translate the message
				DispatchMessage(&amp;msg);          // Dispatch the message
			}
		}
		else            // If there are no messages
		{

			// Draw the scene.  Watch for ESC key and quit messages from DrawGLScene()
			if ((active &amp;&amp; !DrawGLScene()) || keys[VK_ESCAPE])	// Active?  Was there a quit received?
			{
				done = true;                    // ESC or DrawGLScene signalled a quit
			}
			else                                    // Not time to quit, update screen
			{
				SwapBuffers(hDC);               // Swap buffers (double buffering)
				if (keys['B'] &amp;&amp; !bp)
				{
					bp = true;
					blend = !blend;
					if (!blend)
					{
						glDisable(GL_BLEND);
						glEnable(GL_DEPTH_TEST);
					}
					else
					{
						glEnable(GL_BLEND);
						glDisable(GL_DEPTH_TEST);
					}
				}
				if (!keys['B'])
				{
					bp = false;
				}

                                if (keys['I'])
                                {

                                Form1-&gt;ShowModal();
                                }

				if (keys['F'] &amp;&amp; !fp)
				{
					fp = true;
					filter+=1;
					if (filter&gt;2)
					{
						filter=0;
					}
				}
				if (!keys['F'])
				{
					fp = false;
				}

				if (keys[VK_PRIOR])
				{
					z-=0.02f;
				}

				if (keys[VK_NEXT])
				{
					z+=0.02f;
				}

				if (keys[VK_UP])
				{

					xpos -= (float)sin(heading*piover180) * 0.05f;
					zpos -= (float)cos(heading*piover180) * 0.05f;
					if (walkbiasangle &gt;= 359.0f)
					{
						walkbiasangle = 0.0f;
					}
					else
					{
						walkbiasangle+= 10;
					}
					walkbias = (float)sin(walkbiasangle * piover180)/20.0f;
				}

				if (keys[VK_DOWN])
				{
					xpos += (float)sin(heading*piover180) * 0.05f;
					zpos += (float)cos(heading*piover180) * 0.05f;
					if (walkbiasangle &lt;= 1.0f)
					{
						walkbiasangle = 359.0f;
					}
					else
					{
						walkbiasangle-= 10;
					}
					walkbias = (float)sin(walkbiasangle * piover180)/20.0f;
				}

				if (keys[VK_RIGHT])
				{
					heading -= 0.5f;
					yrot = heading;
				}

				if (keys[VK_LEFT])
				{
					heading += 0.5f;
					yrot = heading;
				}

				if (keys[VK_PRIOR])
				{
					lookupdown-= 1.0f;
				}

				if (keys[VK_NEXT])
				{
					lookupdown+= 1.0f;
				}

				if (keys[VK_F1])			// Is F1 neing pressed?
				{
					keys[VK_F1] = false;		// If so make key FALSE
					KillGLWindow();			// Kill our current window
					fullscreen = !fullscreen;	// Toggle fullscreen / windowed mode
					// Recreate our OpenGL window
					if (!CreateGLWindow(&quot;Lionel Brits &amp; NeHe's 3D World Tutorial&quot;,640,480,16,fullscreen))
					{
						return 0;       // Quit if window was not created
					}
				}
			}
		}
	}

	// Shutdown
	KillGLWindow();         // Kill the window
	return (msg.wParam);    // Exit the program
}
//---------------------------------------------------------------------------
</code></pre>
<p>Quelle des OpenGL skeletts:<br />
<a href="http://www.joachimrohde.com/cms/xoops/modules/articles/article.php?id=17" rel="nofollow">http://www.joachimrohde.com/cms/xoops/modules/articles/article.php?id=17</a></p>
]]></description><link>https://www.c-plusplus.net/forum/topic/205419/form-bei-opengl-öffnen</link><generator>RSS for Node</generator><lastBuildDate>Wed, 19 Aug 2026 20:49:00 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/205419.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 14 Feb 2008 00:32:24 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to form bei OpenGL öffnen on Thu, 14 Feb 2008 00:32:24 GMT]]></title><description><![CDATA[<p>hi</p>
<p>hab folgenes problem hoffe mir kann da einer weiterhelfen...</p>
<p>ich habe ein openGL projekt von einem touturial übernommen (quelltext folgt)<br />
und möchte damit dann eine 3d landschaft realisieren die zu durchlaufen ist...<br />
das ganze ist erstellt in dem borland bilder 6.0...<br />
nun möchte ich das mit der taste &quot;i&quot; ein form geöfnet wird wo dann z.b. ein inventar zu sehen ist etc...<br />
das problem ist das wenn ich das form1 mit &quot;ShowModal()&quot; aufrufen will bekomm ich immer die fehlermeldung:<br />
&quot;Im Projekt test.exe ist eine Exception der Klasse EAccessViolation aufgetreten. Meldung: 'Zugriffsverletzung bei Adresse 004022EE. Lesen von Adresse 00000000'. Prozeß wurde angehalten. Mit Einzelne Anweisung oder Start fortsetzen.&quot;</p>
<p>der debuger hält an der stelle Form1-&gt;ShowModal(); an hab in dem Form1 bislang noch nichts drin...</p>
<p>kann mir jemand helfen und mir sagen was ich da falsch gemacht hab oder wie ich ein form in das projekt integrieren kann???</p>
<p>PS: der code von dem toturial selbst also der OpenGL code funktioniert eben nur das aufrufen des forms nicht....</p>
<pre><code>//---------------------------------------------------------------------------

#include &lt;vcl.h&gt;
#include &lt;windows.h&gt;    // Header file for windows
#include &lt;math.h&gt;	// Math library header file
#include &lt;stdio.h&gt;	// Header file for standard Input/Output
#include &lt;gl\gl.h&gt;      // Header file for the OpenGL32 library
#include &lt;gl\glu.h&gt;     // Header file for the GLu32 library
#include &lt;gl\glaux.h&gt;   // Header file for the GLaux library
#include &quot;Unit1.h&quot;
#pragma hdrstop

//---------------------------------------------------------------------------
#pragma argsused

HGLRC hRC = NULL;               // Permanent rendering context
HDC hDC = NULL;                 // Private GDI device context
HWND hWnd = NULL;               // Holds our window handle
HINSTANCE hInstance = NULL;     // Holds the instance of the application

bool keys[256];                 // Array used for the keyboard routine
bool active = true;             // Window active flag set to TRUE by default
bool fullscreen = true;         // Fullscreen flag set to fullscreen mode by default

bool blend;			// Blending ON/OFF
bool bp;			// B pressed?
bool fp;			// F pressed?

const float piover180 = 0.0174532925f;
float heading;
float xpos;
float zpos;

GLfloat	yrot;                   // Y Rotation
GLfloat walkbias = 0;
GLfloat walkbiasangle = 0;
GLfloat lookupdown = 0.0f;
GLfloat	z = 0.0f;               // Depth into the screen

GLuint filter;			// Which filter to use
GLuint texture[3];		// Storage for 3 textures

typedef struct tagVERTEX
{
	float x, y, z;
	float u, v;
} VERTEX;

typedef struct tagTRIANGLE
{
	VERTEX vertex[3];
} TRIANGLE;

typedef struct tagSECTOR
{
	int numtriangles;
	TRIANGLE* triangle;
} SECTOR;

SECTOR sector1;         // Our model goes here:

LRESULT	CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);   // Declaration for WndProc

void readstr(FILE *f,char *string)
{
	do
	{
		fgets(string, 255, f);
	} while ((string[0] == '/') || (string[0] == '\n'));
	return;
}

void SetupWorld()
{
	float x, y, z, u, v;
	int numtriangles;
	FILE *filein;
	char oneline[255];
	filein = fopen(&quot;data/world.txt&quot;, &quot;rt&quot;);	        // File to load world data from

	readstr(filein,oneline);
	sscanf(oneline, &quot;NUMPOLLIES %d\n&quot;, &amp;numtriangles);

	sector1.triangle = new TRIANGLE[numtriangles];
	sector1.numtriangles = numtriangles;
	for (int loop = 0; loop &lt; numtriangles; loop++)
	{
		for (int vert = 0; vert &lt; 3; vert++)
		{
			readstr(filein,oneline);
			sscanf(oneline, &quot;%f %f %f %f %f&quot;, &amp;x, &amp;y, &amp;z, &amp;u, &amp;v);
			sector1.triangle[loop].vertex[vert].x = x;
			sector1.triangle[loop].vertex[vert].y = y;
			sector1.triangle[loop].vertex[vert].z = z;
			sector1.triangle[loop].vertex[vert].u = u;
			sector1.triangle[loop].vertex[vert].v = v;
		}
	}
	fclose(filein);
	return;
}

AUX_RGBImageRec *LoadBMP(char *Filename)                // Loads a bitmap image
{
        FILE *File=NULL;                                // File handle

        if (!Filename)                                  // Make sure a filename was given
        {
                return NULL;                            // If not return NULL
        }

        File=fopen(Filename,&quot;r&quot;);                       // Check to see if the file exists

        if (File)                                       // Does the file exist?
        {
                fclose(File);                           // Close the handle
                return auxDIBImageLoad(Filename);       // Load the bitmap and return a pointer
        }
        return NULL;                                    // If load failed return NULL
}

int LoadGLTextures()                                    // Load bitmaps and convert to textures
{
        int Status = false;                             // Status indicator

        AUX_RGBImageRec *TextureImage[1];               // Create storage space for the texture

        memset(TextureImage,0,sizeof(void *)*1);        // Set the pointer to NULL

        // Load the bitmap, check for errors, if bitmap's not found quit
        if (TextureImage[0]=LoadBMP(&quot;Data/Mud.bmp&quot;))
        {
                Status = true;                          // Set the status to TRUE

                glGenTextures(3, &amp;texture[0]);          // Create three textures

				// Create nearest filtered texture
				glBindTexture(GL_TEXTURE_2D, texture[0]);
				glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
				glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
				glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]-&gt;sizeX, TextureImage[0]-&gt;sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]-&gt;data);

                // Create linear filtered texture
                glBindTexture(GL_TEXTURE_2D, texture[1]);
                glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
                glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
                glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]-&gt;sizeX, TextureImage[0]-&gt;sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]-&gt;data);

				// Create mipmapped texture
				glBindTexture(GL_TEXTURE_2D, texture[2]);
				glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
				glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
				gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]-&gt;sizeX, TextureImage[0]-&gt;sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]-&gt;data);
        }
        if (TextureImage[0])    // If texture exists
        {
                if (TextureImage[0]-&gt;data)      // If texture image exists
                {
                        free(TextureImage[0]-&gt;data);    // Free the texture image memory
                }

                free(TextureImage[0]);          // Free the image structure
        }

        return Status;          // Return the status
}

GLvoid ReSizeGLScene(GLsizei width, GLsizei height)     // Resize and initialize the GL window
{
        if (height == 0)                        // Prevent a divide by zero by
        {
                height = 1;                     // Making height equal One
        }

        glViewport(0, 0, width, height);        // Reset the current viewport

        glMatrixMode(GL_PROJECTION);            // Select the projection matrix
	glLoadIdentity();                       // Reset the projection matrix

	// Calculate the aspect ratio of the window
	gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);

	glMatrixMode(GL_MODELVIEW);             // Select the modelview matrix
	glLoadIdentity();                       // Reset the modelview matrix
}

int InitGL(GLvoid)      // All setup for OpenGL goes here
{
	if (!LoadGLTextures())          // Jump to texture loading routine
	{
		return false;           // If texture didn't load return FALSE
	}

	glEnable(GL_TEXTURE_2D);	        // Enable texture mapping
	glBlendFunc(GL_SRC_ALPHA,GL_ONE);	// Set the blending function for translucency
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);	// This will clear the background color to black
	glClearDepth(1.0);			// Enables clearing of the depth buffer
	glDepthFunc(GL_LESS);			// The type of depth test to do
	glEnable(GL_DEPTH_TEST);		// Enables depth testing
	glShadeModel(GL_SMOOTH);		// Enables smooth color shading
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);	// Really nice perspective calculations

	SetupWorld();

	return TRUE;            // Initialization went OK
}

int DrawGLScene(GLvoid)         // Here's where we do all the drawing
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);     // Clear the screen and the depth buffer
	glLoadIdentity();					// Reset the view

	GLfloat x_m, y_m, z_m, u_m, v_m;
	GLfloat xtrans = -xpos;
	GLfloat ztrans = -zpos;
	GLfloat ytrans = -walkbias-0.25f;
	GLfloat sceneroty = 360.0f - yrot;

	int numtriangles;

	glRotatef(lookupdown,1.0f,0,0);
	glRotatef(sceneroty,0,1.0f,0);

	glTranslatef(xtrans, ytrans, ztrans);
	glBindTexture(GL_TEXTURE_2D, texture[filter]);

	numtriangles = sector1.numtriangles;

	// Process each triangle
	for (int loop_m = 0; loop_m &lt; numtriangles; loop_m++)
	{
		glBegin(GL_TRIANGLES);
			glNormal3f( 0.0f, 0.0f, 1.0f);
			x_m = sector1.triangle[loop_m].vertex[0].x;
			y_m = sector1.triangle[loop_m].vertex[0].y;
			z_m = sector1.triangle[loop_m].vertex[0].z;
			u_m = sector1.triangle[loop_m].vertex[0].u;
			v_m = sector1.triangle[loop_m].vertex[0].v;
			glTexCoord2f(u_m,v_m); glVertex3f(x_m,y_m,z_m);

			x_m = sector1.triangle[loop_m].vertex[1].x;
			y_m = sector1.triangle[loop_m].vertex[1].y;
			z_m = sector1.triangle[loop_m].vertex[1].z;
			u_m = sector1.triangle[loop_m].vertex[1].u;
			v_m = sector1.triangle[loop_m].vertex[1].v;
			glTexCoord2f(u_m,v_m); glVertex3f(x_m,y_m,z_m);

			x_m = sector1.triangle[loop_m].vertex[2].x;
			y_m = sector1.triangle[loop_m].vertex[2].y;
			z_m = sector1.triangle[loop_m].vertex[2].z;
			u_m = sector1.triangle[loop_m].vertex[2].u;
			v_m = sector1.triangle[loop_m].vertex[2].v;
			glTexCoord2f(u_m,v_m); glVertex3f(x_m,y_m,z_m);
		glEnd();
	}
	return true;            // Everything went OK
}

GLvoid KillGLWindow(GLvoid)     // Properly kill the window
{
	if (fullscreen)         // Are we in fullscreen mode?
	{
		ChangeDisplaySettings(NULL,0);  // If so switch back to the desktop
		ShowCursor(true);               // Show mouse pointer
	}

	if (hRC)        // Do we have a rendering context?
	{
		if (!wglMakeCurrent(NULL,NULL))         // Are we able to release the DC and RC contexts?
		{
			MessageBox(NULL,&quot;Release of DC and RC failed.&quot;,&quot;SHUTDOWN ERROR&quot;,MB_OK | MB_ICONINFORMATION);
		}

		if (!wglDeleteContext(hRC))             // Are we able to delete the RC?
		{
			MessageBox(NULL,&quot;Release rendering context failed.&quot;,&quot;SHUTDOWN ERROR&quot;,MB_OK | MB_ICONINFORMATION);
		}
		hRC = NULL;             // Set RC to NULL
	}

	if (hDC &amp;&amp; !ReleaseDC(hWnd,hDC))        // Are we able to release the DC
	{
		MessageBox(NULL,&quot;Release device context failed.&quot;,&quot;SHUTDOWN ERROR&quot;,MB_OK | MB_ICONINFORMATION);
		hDC = NULL;             // Set DC to NULL
	}

	if (hWnd &amp;&amp; !DestroyWindow(hWnd))       // Are we able to destroy the window?
	{
		MessageBox(NULL,&quot;Could not release hWnd.&quot;,&quot;SHUTDOWN ERROR&quot;,MB_OK | MB_ICONINFORMATION);
		hWnd = NULL;            // Set hWnd to NULL
	}

	if (!UnregisterClass(&quot;OpenGL&quot;,hInstance))       // Are we able to unregister class
	{
		MessageBox(NULL,&quot;Could not unregister class.&quot;,&quot;SHUTDOWN ERROR&quot;,MB_OK | MB_ICONINFORMATION);
		hInstance = NULL;       // Set hInstance to NULL
	}
}

/*	This Code Creates Our OpenGL Window.  Parameters Are:
 *	title			- Title To Appear At The Top Of The Window
 *	width			- Width Of The GL Window Or Fullscreen Mode
 *	height			- Height Of The GL Window Or Fullscreen Mode
 *	bits			- Number Of Bits To Use For Color (8/16/24/32)
 *	fullscreenflag	- Use Fullscreen Mode (TRUE) Or Windowed Mode (FALSE)*/

BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag)
{
	GLuint		PixelFormat;		// Holds the results after searching for a match
	WNDCLASS	wc;		        // Windows class structure
	DWORD		dwExStyle;              // Window extended style
	DWORD		dwStyle;                // Window style
	RECT		WindowRect;             // Grabs rctangle upper left / lower right values
	WindowRect.left = (long)0;              // Set left value to 0
	WindowRect.right = (long)width;		// Set right value to requested width
	WindowRect.top = (long)0;               // Set top value to 0
	WindowRect.bottom = (long)height;       // Set bottom value to requested height

	fullscreen = fullscreenflag;              // Set the global fullscreen flag

	hInstance               = GetModuleHandle(NULL);		// Grab an instance for our window
	wc.style                = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;   // Redraw on size, and own DC for window
	wc.lpfnWndProc          = (WNDPROC) WndProc;			// WndProc handles messages
	wc.cbClsExtra           = 0;					// No extra window data
	wc.cbWndExtra           = 0;					// No extra window data
	wc.hInstance            = hInstance;				// Set the Instance
	wc.hIcon                = LoadIcon(NULL, IDI_WINLOGO);		// Load the default icon
	wc.hCursor              = LoadCursor(NULL, IDC_ARROW);		// Load the arrow pointer
	wc.hbrBackground        = NULL;					// No background required for GL
	wc.lpszMenuName		= NULL;					// We don't want a menu
	wc.lpszClassName	= &quot;OpenGL&quot;;				// Set the class name

	if (!RegisterClass(&amp;wc))					// Attempt to register the window class
	{
		MessageBox(NULL,&quot;Failed To Register The Window Class.&quot;,&quot;ERROR&quot;,MB_OK|MB_ICONEXCLAMATION);

		return false;   // Return FALSE
	}

	if (fullscreen)         // Attempt fullscreen mode?
	{
		DEVMODE dmScreenSettings;                                       // Device mode
		memset(&amp;dmScreenSettings,0,sizeof(dmScreenSettings));	        // Makes sure memory's cleared
		dmScreenSettings.dmSize         = sizeof(dmScreenSettings);     // Size of the devmode structure
		dmScreenSettings.dmPelsWidth	= width;                        // Selected screen width
		dmScreenSettings.dmPelsHeight	= height;                       // Selected screen height
		dmScreenSettings.dmBitsPerPel	= bits;	                        // Selected bits per pixel
		dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;

		// Try to set selected mode and get results. NOTE: CDS_FULLSCREEN gets rid of start bar.
		if (ChangeDisplaySettings(&amp;dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)
		{
			// If the mode fails, offer two options. Quit or use windowed mode.
			if (MessageBox(NULL,&quot;The requested fullscreen mode is not supported by\nyour video card. Use windowed mode instead?&quot;,&quot;NeHe GL&quot;,MB_YESNO|MB_ICONEXCLAMATION)==IDYES)
			{
				fullscreen = false;       // Windowed mode selected. Fullscreen = FALSE
			}
			else
			{
				// Pop up a message box letting user know the program is closing.
				MessageBox(NULL,&quot;Program will now close.&quot;,&quot;ERROR&quot;,MB_OK|MB_ICONSTOP);
				return false;           // Return FALSE
			}
		}
	}

	if (fullscreen)                         // Are We Still In Fullscreen Mode?
	{
		dwExStyle = WS_EX_APPWINDOW;    // Window extended style
		dwStyle = WS_POPUP;		// Windows style
		ShowCursor(false);		// Hide mouse pointer
	}
	else
	{
		dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;           // Window extended style
		dwStyle=WS_OVERLAPPEDWINDOW;                            // Windows style
	}

	AdjustWindowRectEx(&amp;WindowRect, dwStyle, FALSE, dwExStyle);     // Adjust window to true requested size

	// Create the window
	if (!(hWnd = CreateWindowEx(dwExStyle,          // Extended Style For The Window
                &quot;OpenGL&quot;,				// Class name
		title,					// Window title
		dwStyle |				// Defined window style
		WS_CLIPSIBLINGS |			// Required window style
		WS_CLIPCHILDREN,			// Required window style
		0, 0,					// Window position
		WindowRect.right-WindowRect.left,	// Calculate window width
		WindowRect.bottom-WindowRect.top,	// Calculate window height
		NULL,					// No parent window
		NULL,					// No menu
		hInstance,				// Instance
		NULL)))					// Dont pass anything to WM_CREATE
	{
		KillGLWindow();                         // Reset the display
		MessageBox(NULL,&quot;Window Creation Error.&quot;,&quot;ERROR&quot;,MB_OK|MB_ICONEXCLAMATION);
		return false;                           // Return FALSE
	}

	static	PIXELFORMATDESCRIPTOR pfd =             // pfd tells windows how we want things to be
	{
		sizeof(PIXELFORMATDESCRIPTOR),          // Size of this pixel format descriptor
		1,					// Version number
		PFD_DRAW_TO_WINDOW |			// Format must support window
		PFD_SUPPORT_OPENGL |			// Format must support OpenGL
		PFD_DOUBLEBUFFER,			// Must support double buffering
		PFD_TYPE_RGBA,				// Request an RGBA format
		bits,					// Select our color depth
		0, 0, 0, 0, 0, 0,			// Color bits ignored
		0,					// No alpha buffer
		0,					// Shift bit ignored
		0,					// No accumulation buffer
		0, 0, 0, 0,				// Accumulation bits ignored
		16,					// 16Bit Z-Buffer (Depth buffer)
		0,					// No stencil buffer
		0,					// No auxiliary buffer
		PFD_MAIN_PLANE,				// Main drawing layer
		0,					// Reserved
		0, 0, 0					// Layer masks ignored
	};

	if (!(hDC=GetDC(hWnd)))         // Did we get a device context?
	{
		KillGLWindow();         // Reset the display
		MessageBox(NULL,&quot;Can't create a GL device context.&quot;,&quot;ERROR&quot;,MB_OK|MB_ICONEXCLAMATION);
		return false;           // Return FALSE
	}

	if (!(PixelFormat=ChoosePixelFormat(hDC,&amp;pfd)))	// Did windows find a matching pixel format?
	{
		KillGLWindow();         // Reset the display
		MessageBox(NULL,&quot;Can't find a suitable pixelformat.&quot;,&quot;ERROR&quot;,MB_OK|MB_ICONEXCLAMATION);
		return false;           // Return FALSE
	}

	if(!SetPixelFormat(hDC,PixelFormat,&amp;pfd))       // Are we able to set the pixel format?
	{
		KillGLWindow();         // Reset the display
		MessageBox(NULL,&quot;Can't set the pixelformat.&quot;,&quot;ERROR&quot;,MB_OK|MB_ICONEXCLAMATION);
		return false;           // Return FALSE
	}

	if (!(hRC=wglCreateContext(hDC)))               // Are we able to get a rendering context?
	{
		KillGLWindow();         // Reset the display
		MessageBox(NULL,&quot;Can't create a GL rendering context.&quot;,&quot;ERROR&quot;,MB_OK|MB_ICONEXCLAMATION);
		return false;           // Return FALSE
	}

	if(!wglMakeCurrent(hDC,hRC))    // Try to activate the rendering context
	{
		KillGLWindow();         // Reset the display
		MessageBox(NULL,&quot;Can't activate the GL rendering context.&quot;,&quot;ERROR&quot;,MB_OK|MB_ICONEXCLAMATION);
		return false;           // Return FALSE
	}

	ShowWindow(hWnd,SW_SHOW);       // Show the window
	SetForegroundWindow(hWnd);      // Slightly higher priority
	SetFocus(hWnd);                 // Sets keyboard focus to the window
	ReSizeGLScene(width, height);   // Set up our perspective GL screen

	if (!InitGL())                  // Initialize our newly created GL window
	{
		KillGLWindow();         // Reset the display
		MessageBox(NULL,&quot;Initialization failed.&quot;,&quot;ERROR&quot;,MB_OK|MB_ICONEXCLAMATION);
		return false;           // Return FALSE
	}

	return true;                    // Success
}

LRESULT CALLBACK WndProc(HWND hWnd,     // Handle for this window
                        UINT uMsg,      // Message for this window
			WPARAM wParam,  // Additional message information
			LPARAM lParam)  // Additional message information
{
	switch (uMsg)                           // Check for windows messages
	{
		case WM_ACTIVATE:               // Watch for window activate message
		{
			if (!HIWORD(wParam))    // Check minimization state
			{
				active = true;  // Program is active
			}
			else
			{
				active = false; // Program is no longer active
			}

			return 0;               // Return to the message loop
		}

		case WM_SYSCOMMAND:             // Intercept system commands
		{
			switch (wParam)         // Check system calls
			{
				case SC_SCREENSAVE:     // Screensaver trying to start?
				case SC_MONITORPOWER:	// Monitor trying to enter powersave?
				return 0;       // Prevent from happening
			}
			break;                  // Exit
		}

		case WM_CLOSE:                  // Did we receive a close message?
		{
			PostQuitMessage(0);     // Send a quit message
			return 0;               // Jump back
		}

		case WM_KEYDOWN:                // Is a key being held down?
		{
			keys[wParam] = true;    // If so, mark it as TRUE
			return 0;               // Jump back
		}

		case WM_KEYUP:                  // Has a key been released?
		{
			keys[wParam] = false;   // If so, mark it as FALSE
			return 0;               // Jump back
		}

		case WM_SIZE:                   // Resize the OpenGL window
		{
			ReSizeGLScene(LOWORD(lParam),HIWORD(lParam));  // LoWord = Width, HiWord = Height
			return 0;               // Jump back
		}
	}

	// Pass all unhandled messages to DefWindowProc
	return DefWindowProc(hWnd,uMsg,wParam,lParam);
}

WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
        MSG msg;                // Windows message structure
	bool done = false;      // Bool variable to exit loop

	// Ask the user which screen mode they prefer
	if (MessageBox(NULL,&quot;Would you like to run in fullscreen mode?&quot;, &quot;Start FullScreen?&quot;,MB_YESNO|MB_ICONQUESTION)==IDNO)
	{
		fullscreen = false;       // Windowed mode
	}

	// Create our OpenGL window
	if (!CreateGLWindow(&quot;Lionel Brits &amp; NeHe's 3D World Tutorial&quot;,640,480,16,fullscreen))
	{
		return 0;               // Quit if window was not created
	}

	while(!done)            // Loop that runs while done = FALSE
	{
		if (PeekMessage(&amp;msg,NULL,0,0,PM_REMOVE))	// Is there a message waiting?
		{
			if (msg.message == WM_QUIT)             // Have we received a quit message?
			{
				done = true;                    // If so done = TRUE
			}
			else                                    // If not, deal with window messages
			{
				TranslateMessage(&amp;msg);         // Translate the message
				DispatchMessage(&amp;msg);          // Dispatch the message
			}
		}
		else            // If there are no messages
		{

			// Draw the scene.  Watch for ESC key and quit messages from DrawGLScene()
			if ((active &amp;&amp; !DrawGLScene()) || keys[VK_ESCAPE])	// Active?  Was there a quit received?
			{
				done = true;                    // ESC or DrawGLScene signalled a quit
			}
			else                                    // Not time to quit, update screen
			{
				SwapBuffers(hDC);               // Swap buffers (double buffering)
				if (keys['B'] &amp;&amp; !bp)
				{
					bp = true;
					blend = !blend;
					if (!blend)
					{
						glDisable(GL_BLEND);
						glEnable(GL_DEPTH_TEST);
					}
					else
					{
						glEnable(GL_BLEND);
						glDisable(GL_DEPTH_TEST);
					}
				}
				if (!keys['B'])
				{
					bp = false;
				}

                                if (keys['I'])
                                {

                                Form1-&gt;ShowModal();
                                }

				if (keys['F'] &amp;&amp; !fp)
				{
					fp = true;
					filter+=1;
					if (filter&gt;2)
					{
						filter=0;
					}
				}
				if (!keys['F'])
				{
					fp = false;
				}

				if (keys[VK_PRIOR])
				{
					z-=0.02f;
				}

				if (keys[VK_NEXT])
				{
					z+=0.02f;
				}

				if (keys[VK_UP])
				{

					xpos -= (float)sin(heading*piover180) * 0.05f;
					zpos -= (float)cos(heading*piover180) * 0.05f;
					if (walkbiasangle &gt;= 359.0f)
					{
						walkbiasangle = 0.0f;
					}
					else
					{
						walkbiasangle+= 10;
					}
					walkbias = (float)sin(walkbiasangle * piover180)/20.0f;
				}

				if (keys[VK_DOWN])
				{
					xpos += (float)sin(heading*piover180) * 0.05f;
					zpos += (float)cos(heading*piover180) * 0.05f;
					if (walkbiasangle &lt;= 1.0f)
					{
						walkbiasangle = 359.0f;
					}
					else
					{
						walkbiasangle-= 10;
					}
					walkbias = (float)sin(walkbiasangle * piover180)/20.0f;
				}

				if (keys[VK_RIGHT])
				{
					heading -= 0.5f;
					yrot = heading;
				}

				if (keys[VK_LEFT])
				{
					heading += 0.5f;
					yrot = heading;
				}

				if (keys[VK_PRIOR])
				{
					lookupdown-= 1.0f;
				}

				if (keys[VK_NEXT])
				{
					lookupdown+= 1.0f;
				}

				if (keys[VK_F1])			// Is F1 neing pressed?
				{
					keys[VK_F1] = false;		// If so make key FALSE
					KillGLWindow();			// Kill our current window
					fullscreen = !fullscreen;	// Toggle fullscreen / windowed mode
					// Recreate our OpenGL window
					if (!CreateGLWindow(&quot;Lionel Brits &amp; NeHe's 3D World Tutorial&quot;,640,480,16,fullscreen))
					{
						return 0;       // Quit if window was not created
					}
				}
			}
		}
	}

	// Shutdown
	KillGLWindow();         // Kill the window
	return (msg.wParam);    // Exit the program
}
//---------------------------------------------------------------------------
</code></pre>
<p>Quelle des OpenGL skeletts:<br />
<a href="http://www.joachimrohde.com/cms/xoops/modules/articles/article.php?id=17" rel="nofollow">http://www.joachimrohde.com/cms/xoops/modules/articles/article.php?id=17</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1455529</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1455529</guid><dc:creator><![CDATA[PatrickHofmann]]></dc:creator><pubDate>Thu, 14 Feb 2008 00:32:24 GMT</pubDate></item><item><title><![CDATA[Reply to form bei OpenGL öffnen on Thu, 14 Feb 2008 22:18:46 GMT]]></title><description><![CDATA[<p>Die Form existiert beim Aufruf von ShowModal offenbar nicht.</p>
<p>Insgesamt sieht diese Mischung aus WinAPI und VCL recht krude aus. Im examples-Verzeichnis des BCB6 gibt es auch ein paar OpenGL-Projekte, da kannst du sicher Anregungen für die &quot;korrekte&quot; Kombination von VCL und OpenGL entnehmen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1456233</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1456233</guid><dc:creator><![CDATA[Jansen]]></dc:creator><pubDate>Thu, 14 Feb 2008 22:18:46 GMT</pubDate></item><item><title><![CDATA[Reply to form bei OpenGL öffnen on Thu, 14 Feb 2008 23:56:23 GMT]]></title><description><![CDATA[<p>oh danke ja so gehts zumindest ohne fehlermeldung wenn ich das Form1 mit</p>
<pre><code class="language-cpp">Application-&gt;Initialize();
Application-&gt;CreateForm(__classid(TForm1), &amp;Form1);
Application-&gt;Run();
</code></pre>
<p>öffne. aber dann kann ichs auch nicht mehr zumachen ohne alles zu schliesen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
<p>kann mir jemand nen beispiel zeigen wie ichüber ein form das opengl fenser aufmach und wie ich von dem opengl fenster aus ein form öfnen kann habs nun schon den ganzen abend auf verschiedene weisen versucht....</p>
<blockquote>
<p>Im examples-Verzeichnis des BCB6 gibt es auch ein paar OpenGL-Projekte, da kannst du sicher Anregungen für die &quot;korrekte&quot; Kombination von VCL und OpenGL entnehmen.</p>
</blockquote>
<p>wo genau?habs nicht gefunden. kannst mir nen link geben??</p>
<p>mfg<br />
patrick</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1456255</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1456255</guid><dc:creator><![CDATA[patrickhofmann]]></dc:creator><pubDate>Thu, 14 Feb 2008 23:56:23 GMT</pubDate></item><item><title><![CDATA[Reply to form bei OpenGL öffnen on Fri, 15 Feb 2008 07:50:29 GMT]]></title><description><![CDATA[<p><span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>P</mi><mi>f</mi><mi>a</mi><mi>d</mi></mrow><annotation encoding="application/x-tex">Pfad</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.69444em;"></span><span class="strut bottom" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.13889em;">P</span><span class="mord mathit" style="margin-right:0.10764em;">f</span><span class="mord mathit">a</span><span class="mord mathit">d</span></span></span></span>\CBuilder6\Examples\OpenGL</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1456295</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1456295</guid><dc:creator><![CDATA[Jansen]]></dc:creator><pubDate>Fri, 15 Feb 2008 07:50:29 GMT</pubDate></item><item><title><![CDATA[Reply to form bei OpenGL öffnen on Fri, 20 Jun 2008 06:56:17 GMT]]></title><description><![CDATA[<p>oh a h so danke dachte du meinst im netz wuste garnicht das da auch beispiele bei sind ok gug mir das an und versuchs zu übertragen und meld mich wenn ich noch probleme hab ...</p>
<p>danke...</p>
<p>mfg<br />
patrick</p>
<p><strong>EDIT:</strong><br />
Thread geschlossen da SpamBot-Ziel. Eventuelle Nachfragen ausnahmsweise in einem neuen Thread stellen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1458018</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1458018</guid><dc:creator><![CDATA[patrickhofmann]]></dc:creator><pubDate>Fri, 20 Jun 2008 06:56:17 GMT</pubDate></item></channel></rss>