Einfachkrank
2002-08-21, 21:55:56
Hier erstmal Code:
// Datei: Main.cpp
# include <stdio.h>
# include <stdlib.h>
# include <windows.h>
# include <gl/gl.h>
# include <gl/glu.h>
# include <gl/glaux.h>
# define WIN32_LEAN_AND_MEAN
BOOL isdone = FALSE;
HWND hwnd;
HDC hdc;
HGLRC hrc;
GLfloat angle = 0;
float ambientLight[] = { 0.25f, 0.25f, 1.0f, 1.0f };
float diffuseLight[] = { 0.25f, 0.25f, 1.0f, 1.0f };
float lightPosition[] = { 0.0f, 0.0f, 1.0f, 0.0f };
float matAmbient[] = { 1.0f, 1.0f, 1.0f, 1.0f };
float matDiff[] = { 1.0f, 1.0f, 1.0f, 1.0f};
LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
{
FILE *file;
switch(wparam)
{
case WM_KEYDOWN:
switch(wparam)
{
case VK_ESCAPE:
isdone = TRUE;
file = fopen("Protokoll011.txt", "w");
fprintf(file, "Escape Press \t OK");
fclose(file);
return 0;
break;
default: break;
}
default: break;
}
return (DefWindowProc(hwnd, message, wparam, lparam));
} // CALLBACK
// DAS HIER IST AUS EINEM BEISPIEL VON "OpenGL Game Programming"
void DrawCube(float xPos, float yPos, float zPos)
{
glPushMatrix();
glTranslatef(xPos, yPos, zPos);
glBegin(GL_POLYGON);
glNormal3f(0.0f, 1.0f, 0.0f); // top face
glVertex3f(0.5f, 0.5f, 0.5f);
glVertex3f(0.5f, 0.5f, -0.5f);
glVertex3f(-0.5f, 0.5f, -0.5f);
glVertex3f(-0.5f, 0.5f, 0.5f);
glEnd();
glBegin(GL_POLYGON);
glNormal3f(0.0f, 0.0f, 1.0f); // front face
glVertex3f(0.5f, 0.5f, 0.5f);
glVertex3f(-0.5f, 0.5f, 0.5f);
glVertex3f(-0.5f, -0.5f, 0.5f);
glVertex3f(0.5f, -0.5f, 0.5f);
glEnd();
glBegin(GL_POLYGON);
glNormal3f(1.0f, 0.0f, 0.0f); // right face
glVertex3f(0.5f, 0.5f, 0.5f);
glVertex3f(0.5f, -0.5f, 0.5f);
glVertex3f(0.5f, -0.5f, -0.5f);
glVertex3f(0.5f, 0.5f, -0.5f);
glEnd();
glBegin(GL_POLYGON);
glNormal3f(-1.0f, 0.0f, 0.0f); // left face
glVertex3f(-0.5f, 0.5f, 0.5f);
glVertex3f(-0.5f, 0.5f, -0.5f);
glVertex3f(-0.5f, -0.5f, -0.5f);
glVertex3f(-0.5f, -0.5f, 0.5f);
glEnd();
glBegin(GL_POLYGON);
glNormal3f(0.0f, -1.0f, 0.0f); // bottom face
glVertex3f(-0.5f, -0.5f, 0.5f);
glVertex3f(-0.5f, -0.5f, -0.5f);
glVertex3f(0.5f, -0.5f, -0.5f);
glVertex3f(0.5f, -0.5f, 0.5f);
glEnd();
glBegin(GL_POLYGON);
glNormal3f(0.0f, 0.0f, -1.0f); // back face
glVertex3f(0.5f, -0.5f, -0.5f);
glVertex3f(-0.5f, -0.5f, -0.5f);
glVertex3f(-0.5f, 0.5f, -0.5f);
glVertex3f(0.5f, 0.5f, -0.5f);
glEnd();
glPopMatrix();
} // Draw_Cube
void Render()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
angle = angle + 0.1f;
if (angle >= 360.0f)
angle = 0.0f;
glTranslatef(0.0f, 0.0f, -15.0f);
glRotatef(angle, 1.0f, 0.0f, 0.0f);
glRotatef(angle, 0.0f, 1.0f, 0.0f);
glRotatef(angle, 0.0f, 0.0f, 1.0f);
DrawCube(0.0f, 0.0f, 0.0f);
glFlush();
SwapBuffers(hdc);
} // Render
// HIER ENDE DER KOPIE
int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hprevinst, LPSTR lpcmdline, int nshowcmd)
{
WNDCLASSEX winclass;
MSG message;
char szclassname[] = "OpenGL by Michael Eberhardt alias Einfachkrank";
RECT windowRect;
FILE *file;
windowRect.left = (long)0;
windowRect.right = (long)1024;
windowRect.top = (long)0;
windowRect.bottom = (long)768;
winclass.cbSize = sizeof(WNDCLASSEX);
winclass.cbClsExtra = 0;
winclass.cbWndExtra = 0;
winclass.hbrBackground = NULL;
winclass.hCursor = LoadCursor(NULL, IDC_ARROW);
winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
winclass.hInstance = hinst;
winclass.lpfnWndProc = WindowProc;
winclass.lpszClassName = szclassname;
winclass.lpszMenuName = NULL;
winclass.style = CS_VREDRAW | CS_HREDRAW | CS_OWNDC;
if(!(RegisterClassEx(&winclass)))
return 0;
file = fopen("Protokoll.txt", "w");
fprintf(file, "RegisterClassEx \t OK\n");
DEVMODE devmode;
devmode.dmSize = sizeof(DEVMODE);
devmode.dmBitsPerPel = 16;
devmode.dmPelsWidth = 1024;
devmode.dmPelsHeight = 768;
devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;
if((ChangeDisplaySettings(&devmode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL))
{
MessageBox(hwnd, "ChangeDisplaySettings FAILED", "ERROR", MB_OK | MB_ICONERROR);
return 0;
}
fprintf(file, "ChangeDisplaySettings \t OK\n");
AdjustWindowRectEx(&windowRect, WS_POPUP, NULL, WS_EX_APPWINDOW);
fprintf(file, "Adjust WindowRect \t OK\n");
hdc = GetDC(hwnd);
fprintf(file, "GetDC \t OK\n");
int iPixelFormat;
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
16,
0, 0, 0, 0, 0, 0,
0, 0, 0,
0, 0, 0, 0,
16,
0, 0,
PFD_MAIN_PLANE,
0, 0, 0, 0};
iPixelFormat = ChoosePixelFormat(hdc, &pfd);
SetPixelFormat(hdc, iPixelFormat, &pfd);
fprintf(file, "PixelFormat Choose + Set \t OK\n");
hrc = wglCreateContext(hdc);
wglMakeCurrent(hdc, hrc);
fprintf(file, "wglContext Create + Current \t OK\n");
glViewport(0, 0, 1024, 768);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(54.0f, (GLfloat)1024 / (GLfloat)768, 1.0f, 1000.0f);
fprintf(file, "Viewport + gluPerspektive \t OK\n");
hwnd = CreateWindowEx(NULL, szclassname, szclassname,
WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
0, 0, 1, 1, NULL, NULL, hinst, NULL);
if(!hwnd)
{
MessageBox(hwnd, "CreateWindowEx FAILED", "ERROR", MB_OK | MB_ICONERROR);
wglMakeCurrent(hdc, hrc);
wglDeleteContext(hrc);
ReleaseDC(hwnd, hdc);
return 0;
}
fprintf(file, "HWND ertzeugen \t OK\n");
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glFrontFace(GL_CCW);
glEnable(GL_LIGHTING);
glMaterialfv(GL_FRONT, GL_AMBIENT, matAmbient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, matDiff);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
glEnable(GL_LIGHT0);
ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
ShowCursor(FALSE);
fprintf(file, "Window Update Show \t OK´\nHauptschleife gestartet\n");
fclose(file);
BOOL prot = TRUE;
while(!isdone)
{
if(PeekMessage(&message, NULL, 0, 0, PM_REMOVE))
{
fprintf(file, "PeekMessage\n");
TranslateMessage(&message);
DispatchMessage(&message);
}
Render();
}
file = fopen("Protokoll2.txt", "w");
fprintf(file, "Ende Hauptschleife \t OK\n");
ShowCursor(TRUE);
wglMakeCurrent(hdc, hrc);
wglDeleteContext(hrc);
ReleaseDC(hwnd, hdc);
fprintf(file, "Releasings \t OK\n");
fclose(file);
return message.wParam;
} // WinMain
Mein Betriebssystem: WinMe
Mein Hardware: AMD Athlon 700
256 SD-RAM
Voodoo 5 5500
Asus k7V Mainboard
Fehler: Reagiert auf nichts mehr, kein Bluescreen, keine anderen
Fehlermeldungen
vBulletin®, Copyright ©2000-2024, Jelsoft Enterprises Ltd.