ďťż

Ładny brzuch

Czy możecie mi powiedzieć gdzie popełniłem błąd.
Kod kompiluje Visualem 6.
#include <windows.h> #include <stdio.h> #include <gl\gl.h> #include <gl\glu.h> #include <gl\glaux.h> HDC hDC=NULL; HGLRC hRC=NULL; HWND hWnd=NULL; HINSTANCE hInstance; bool keys[256]; bool active=TRUE; bool fullscreen=TRUE; GLuint texture[7]; float obrot; float obroty; float przod = 0.0f; float tyl = -1.0f; float lewa; float prawa; float gora = 0.0f; float dol = -1.0f; //GLfloat lightPos[] = { 0.0f, 0.0f, 75.0f, 1.0f}; //GLfloat specular[] = { 1.0f, 1.0f, 1.0f, 1.0f}; //GLfloat specref[] = { 1.0f, 1.0f, 1.0f, 1.0f}; //GLfloat ambientLight[] = { 0.5f, 0.5f, 0.5f, 1.0f}; //GLfloat spotDir[] = { 0.0f, 0.0f, -1.0f}; LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); AUX_RGBImageRec *LoadBMP(char *Filename) { FILE *File=NULL; if (!Filename) { return NULL; } File=fopen(Filename,"r"); if (File) { fclose(File); return auxDIBImageLoad(Filename); } return NULL; } int LoadGLTextures() { int Status=FALSE; AUX_RGBImageRec *TextureImage[7]; memset(TextureImage,0,sizeof(void *)*1); if (TextureImage[0]=LoadBMP("k1.bmp")) { Status=TRUE; glGenTextures(1, &texture[0]); glBindTexture(GL_TEXTURE_2D, texture[0]); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); } if (TextureImage[0]) { if (TextureImage[0]->data) { free(TextureImage[0]->data); } free(TextureImage[0]); } if (TextureImage[1]=LoadBMP("k2.bmp")) { Status=TRUE; glGenTextures(1, &texture[1]); glBindTexture(GL_TEXTURE_2D, texture[1]); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[1]->sizeX, TextureImage[1]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[1]->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); } if (TextureImage[1]) { if (TextureImage[1]->data) { free(TextureImage[1]->data); } free(TextureImage[1]); } if (TextureImage[2]=LoadBMP("k3.bmp")) { Status=TRUE; glGenTextures(1, &texture[2]); glBindTexture(GL_TEXTURE_2D, texture[2]); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[2]->sizeX, TextureImage[2]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[2]->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); } if (TextureImage[2]) { if (TextureImage[2]->data) { free(TextureImage[2]->data); } free(TextureImage[2]); } if (TextureImage[3]=LoadBMP("k4.bmp")) { Status=TRUE; glGenTextures(1, &texture[3]); glBindTexture(GL_TEXTURE_2D, texture[3]); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[3]->sizeX, TextureImage[3]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[3]->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); } if (TextureImage[3]) { if (TextureImage[3]->data) { free(TextureImage[3]->data); } free(TextureImage[3]); } if (TextureImage[4]=LoadBMP("k5.bmp")) { Status=TRUE; glGenTextures(1, &texture[4]); glBindTexture(GL_TEXTURE_2D, texture[4]); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[4]->sizeX, TextureImage[4]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[4]->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); } if (TextureImage[4]) { if (TextureImage[4]->data) { free(TextureImage[4]->data); } free(TextureImage[4]); } if (TextureImage[5]=LoadBMP("k6.bmp")) { Status=TRUE; glGenTextures(1, &texture[5]); glBindTexture(GL_TEXTURE_2D, texture[5]); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[5]->sizeX, TextureImage[5]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[5]->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); } if (TextureImage[5]) { if (TextureImage[5]->data) { free(TextureImage[5]->data); } free(TextureImage[5]); } if (TextureImage[6]=LoadBMP("drewno.bmp")) { Status=TRUE; glGenTextures(1, &texture[6]); glBindTexture(GL_TEXTURE_2D, texture[6]); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[6]->sizeX, TextureImage[6]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[6]->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); } if (TextureImage[6]) { if (TextureImage[6]->data) { free(TextureImage[6]->data); } free(TextureImage[6]); } return Status; } GLvoid ReSizeGLScene(GLsizei width, GLsizei height) { if (height==0) { height=1; } glViewport(0,0,width,height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } int InitGL(GLvoid) { if (!LoadGLTextures()) { return FALSE; } glEnable(GL_TEXTURE_2D); glShadeModel(GL_SMOOTH); //Czyszczenie glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); //glFrontFace(GL_CCW); //glEnable(GL_CULL_FACE); //glEnable(GL_LIGHTING); //glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientLight); //glLightfv(GL_LIGHTING, GL_DIFFUSE, ambientLight); //glLightfv(GL_LIGHTING, GL_SPECULAR, specular); //glLightfv(GL_LIGHTING, GL_POSITION, lightPos); //glLightf(GL_LIGHTING, GL_SPOT_CUTOFF, 60.0f); //glEnable(GL_LIGHTING); //glEnable(GL_COLOR_MATERIAL); //glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); //glMaterialfv(GL_FRONT, GL_SPECULAR, specref); //glMateriali(GL_FRONT, GL_SHININESS, 128); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glDepthFunc(GL_LEQUAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); return TRUE; } int DrawGLScene(GLvoid) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glTranslatef(0.0f,0.0f,-5.0f); glPushMatrix(); glRotatef(obroty, 1.0,0.0,0.0); glRotatef(obrot, 0.0,0.5,0.0); glBindTexture(GL_TEXTURE_2D, texture[0]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -1.0f, przod); glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.0f, przod); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 0.0f, przod); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, przod); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[5]); glBegin(GL_QUADS); glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.0f, -1.0f, tyl); glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.0f, 0.0f, tyl); glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 0.0f, tyl); glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, tyl); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[2]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, gora, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, gora, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, gora, -1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, gora, 0.0f); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[3]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, dol, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, dol, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, dol, -1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, dol, 0.0f); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[1]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f( lewa, 0.0f, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( lewa, 0.0f, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( lewa, -1.0f, -1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( lewa, -1.0f, 0.0f); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[4]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f( prawa, 0.0f, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( prawa, 0.0f, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( prawa, -1.0f, -1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( prawa, -1.0f, 0.0f); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[6]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f( -2.0f, -1.0f, +2.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( -2.0f, -1.0f, -3.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 3.0f, -1.0f, -3.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 3.0f, -1.0f, +2.0f); glEnd(); obrot += 0.25; if(obroty <= 30) { obroty+=0.75 ; } return TRUE; } GLvoid KillGLWindow(GLvoid) { if (fullscreen) { ChangeDisplaySettings(NULL,0); ShowCursor(TRUE); } if (hRC) { if (!wglMakeCurrent(NULL,NULL)) { MessageBox(NULL,"Release Of DC And RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); } if (!wglDeleteContext(hRC)) { MessageBox(NULL,"Release Rendering Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); } hRC=NULL; } if (hDC && !ReleaseDC(hWnd,hDC)) { MessageBox(NULL,"Release Device Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); hDC=NULL; } if (hWnd && !DestroyWindow(hWnd)) { MessageBox(NULL,"Could Not Release hWnd.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); hWnd=NULL; } if (!UnregisterClass("OpenGL",hInstance)) { MessageBox(NULL,"Could Not Unregister Class.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); hInstance=NULL; } } BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag) { GLuint PixelFormat; WNDCLASS wc; DWORD dwExStyle; DWORD dwStyle; RECT WindowRect; WindowRect.left=(long)0; WindowRect.right=(long)width; WindowRect.top=(long)0; WindowRect.bottom=(long)height; fullscreen=fullscreenflag; hInstance = GetModuleHandle(NULL); wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wc.lpfnWndProc = (WNDPROC) WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = NULL; wc.lpszMenuName = NULL; wc.lpszClassName = "OpenGL"; if (!RegisterClass(&wc)) { MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; } if (fullscreen) { DEVMODE dmScreenSettings; memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); dmScreenSettings.dmSize=sizeof(dmScreenSettings); dmScreenSettings.dmPelsWidth = width; dmScreenSettings.dmPelsHeight = height; dmScreenSettings.dmBitsPerPel = bits; dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT; if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL) { if (MessageBox(NULL,"The Requested Fullscreen Mode Is Not Supported By\nYour Video Card. Use Windowed Mode Instead?","NeHe GL",MB_YESNO|MB_ICONEXCLAMATION)==IDYES) { fullscreen=FALSE; } else { MessageBox(NULL,"Program Will Now Close.","ERROR",MB_OK|MB_IConstop); return FALSE; } } } if (fullscreen) { dwExStyle=WS_EX_APPWINDOW; dwStyle=WS_POPUP; ShowCursor(FALSE); } else { dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; dwStyle=WS_OVERLAPPEDWINDOW; } AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); if (!(hWnd=CreateWindowEx( dwExStyle, "OpenGL", title, dwStyle | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, WindowRect.right-WindowRect.left, WindowRect.bottom-WindowRect.top, NULL, NULL, hInstance, NULL))) { KillGLWindow(); MessageBox(NULL,"Błąd tworzenia okna","BŁĄD",MB_OK|MB_ICONEXCLAMATION); return FALSE; } static PIXELFORMATDESCRIPTOR pfd= { sizeof(PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, PFD_TYPE_RGBA, bits, 0, 0, 0, 0, 0, 0, 0, 32, // może być 16 0, 0, PFD_MAIN_PLANE, 0, 0, 0, 0 }; if (!(hDC=GetDC(hWnd))) { KillGLWindow(); MessageBox(NULL,"Can't Create A GL Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; } if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd))) { KillGLWindow(); MessageBox(NULL,"Can't Find A Suitable PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; } if(!SetPixelFormat(hDC,PixelFormat,&pfd)) { KillGLWindow(); MessageBox(NULL,"Can't Set The PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; } if (!(hRC=wglCreateContext(hDC))) { KillGLWindow(); MessageBox(NULL,"Can't Create A GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; } if(!wglMakeCurrent(hDC,hRC)) { KillGLWindow(); MessageBox(NULL,"Can't Activate The GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; } ShowWindow(hWnd,SW_SHOW); SetForegroundWindow(hWnd); SetFocus(hWnd); ReSizeGLScene(width, height); if (!InitGL()) { KillGLWindow(); MessageBox(NULL,"Błąd inicjalizacji. Pewnie brak textur.","Błąd",MB_OK|MB_ICONEXCLAMATION); return FALSE; } return TRUE; } LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_ACTIVATE: { if (!HIWORD(wParam)) { active=TRUE; } else { active=FALSE; } return 0; } case WM_SYSCOMMAND: { switch (wParam) { case SC_SCREENSAVE: case SC_MONITORPOWER: return 0; } break; } case WM_CLOSE: { PostQuitMessage(0); return 0; } case WM_KEYDOWN: { keys[wParam] = TRUE; return 0; } case WM_KEYUP: { keys[wParam] = FALSE; return 0; } case WM_SIZE: { ReSizeGLScene(LOWORD(lParam),HIWORD(lParam)); return 0; } } return DefWindowProc(hWnd,uMsg,wParam,lParam); } int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MSG msg; BOOL done=FALSE; if (MessageBox(NULL,"Czy chcesz uruchomić w pełnym oknie?", "Pełne okno?",MB_YESNO|MB_ICONQUESTION)==IDNO) { fullscreen=FALSE; } if (!CreateGLWindow("Kostka",1024,768,32,fullscreen)) { return 0; } while(!done) { if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { if (msg.message==WM_QUIT) { done=TRUE; } else { TranslateMessage(&msg); DispatchMessage(&msg); } } //else //{ //if ((active && !DrawGLScene()) || keys[VK_ESCAPE]) //{ // done=TRUE; //} //else //{ // SwapBuffers(hDC); //} if(keys[VK_ESCAPE]) { for(int i=0;i==90;i++) { przod += 0.1f; tyl -= 0.1f; lewa -= 0.1f; prawa += 0.1f; gora += 0.1f; dol -= 0.1f; } } else { SwapBuffers(hDC); } if(active && !DrawGLScene()) { done=TRUE; } else { SwapBuffers(hDC); } } if (keys[VK_F1]) { keys[VK_F1]=FALSE; KillGLWindow(); fullscreen=!fullscreen; if (!CreateGLWindow("Kostka",1024,768,32,fullscreen)) { return 0; } } } } KillGLWindow(); return (msg.wParam); }
Wyskakują mi błędy:
D:\Documents and Settings\Mateusz\Pulpit\na infe\Lesson03\lesson3.cpp(705) : error C2143: syntax error : missing ';' before '}'
D:\Documents and Settings\Mateusz\Pulpit\na infe\Lesson03\lesson3.cpp(705) : error C2143: syntax error : missing ';' before '}'
D:\Documents and Settings\Mateusz\Pulpit\na infe\Lesson03\lesson3.cpp(705) : error C2143: syntax error : missing ';' before '}'
D:\Documents and Settings\Mateusz\Pulpit\na infe\Lesson03\lesson3.cpp(708) : error C2556: 'int __cdecl KillGLWindow(void)' : overloaded function differs only by return type from 'void __cdecl KillGLWindow(void)'
D:\Documents and Settings\Mateusz\Pulpit\na infe\Lesson03\lesson3.cpp(354) : see declaration of 'KillGLWindow'
D:\Documents and Settings\Mateusz\Pulpit\na infe\Lesson03\lesson3.cpp(708) : error C2371: 'KillGLWindow' : redefinition; different basic types
D:\Documents and Settings\Mateusz\Pulpit\na infe\Lesson03\lesson3.cpp(354) : see declaration of 'KillGLWindow'
D:\Documents and Settings\Mateusz\Pulpit\na infe\Lesson03\lesson3.cpp(709) : error C2143: syntax error : missing ';' before 'return'
D:\Documents and Settings\Mateusz\Pulpit\na infe\Lesson03\lesson3.cpp(710) : error C2143: syntax error : missing ';' before '}'
D:\Documents and Settings\Mateusz\Pulpit\na infe\Lesson03\lesson3.cpp(710) : error C2143: syntax error : missing ';' before '}'
D:\Documents and Settings\Mateusz\Pulpit\na infe\Lesson03\lesson3.cpp(710) : error C2143: syntax error : missing ';' before '}'
Error executing cl.exe.
Użytkownik Kubek_pl edytował ten post 07 czerwiec 2005, 16:57


Po co robisz tekie zaawanoswane programy (sciągasz) jak nie rozumiesz błedów u dołu :)
naucz sie podstaw!!!!!!!!

D:\Documents and Settings\Mateusz\Pulpit\na infe\lesson3.cpp(704) : error C2143: syntax error : missing ';' before '}'

ten bład znaczy :

ze w 704 lini brakuje sreednika :)

Popełniłes błąd zaczynając od nauki OpenGL nie znając C++ :]

Najpierw C++ potem API graficzne

A co do C++ polecam : THinking in C++

a wogole to nie sciągajcie kodów których w pełni nie rozumiecie !!!!!!!!!
bo to tylko zasmiecanie forum !



Po pierwsze kod napisałem sam. Po drugie spójrz błą zaczyna się w lini gdzie jest znak
}
A c++ znam i wiem co to za błąd. Zmieniłem kod aplikacji i zedytowałem troche tamten post gdzie był on umieszczony. Pomóżcie mi :pomocy:

Jak znasz C++ to z takimi błędami problemu nie powinno być. Znasz angielski? Poczytaj o błędach w danej lini i masz rozwiązanie. Jeden z błędów mówi o tym że zwracasz zły typ. Jak ten wyeliminujesz to reszta powinna ładnie pójść (chyba ;))

Naprawiłem powyższe błędy lecz nie działa to o co mi chodziło.
Wynikiem programu jest zademonstrowanie kostki która obraca się wraz z deską na której leży.http://forum.ks-ekspert.pl/index.php?
IPB
Mnianowicie po naciśnięci ESC do zmiennych przod, tyl, gora, dol powinna dodawać się się wartość 0.1. Chodzi mi oto aby każda ścina poszła w swoją stronę(prawa w prawo, lewa w lewo, górna w góre itd.). Możecie mi napisać jak to zrobić :pomocy:

#include <windows.h> #include <stdio.h> #include <gl\gl.h> #include <gl\glu.h> #include <gl\glaux.h> HDC hDC=NULL; HGLRC hRC=NULL; HWND hWnd=NULL; HINSTANCE hInstance; bool keys[256]; bool active=TRUE; bool fullscreen=TRUE; GLuint texture[7]; float obrot; float obroty; float przod = 0.0f; float tyl = -1.0f; float lewa; float prawa; float gora = 0.0f; float dol = -1.0f; //GLfloat lightPos[] = { 0.0f, 0.0f, 75.0f, 1.0f}; //GLfloat specular[] = { 1.0f, 1.0f, 1.0f, 1.0f}; //GLfloat specref[] = { 1.0f, 1.0f, 1.0f, 1.0f}; //GLfloat ambientLight[] = { 0.5f, 0.5f, 0.5f, 1.0f}; //GLfloat spotDir[] = { 0.0f, 0.0f, -1.0f}; LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); AUX_RGBImageRec *LoadBMP(char *Filename) { FILE *File=NULL; if (!Filename) { return NULL; } File=fopen(Filename,"r"); if (File) { fclose(File); return auxDIBImageLoad(Filename); } return NULL; } int LoadGLTextures() { int Status=FALSE; AUX_RGBImageRec *TextureImage[7]; memset(TextureImage,0,sizeof(void *)*1); if (TextureImage[0]=LoadBMP("k1.bmp")) { Status=TRUE; glGenTextures(1, &texture[0]); glBindTexture(GL_TEXTURE_2D, texture[0]); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); } if (TextureImage[0]) { if (TextureImage[0]->data) { free(TextureImage[0]->data); } free(TextureImage[0]); } if (TextureImage[1]=LoadBMP("k2.bmp")) { Status=TRUE; glGenTextures(1, &texture[1]); glBindTexture(GL_TEXTURE_2D, texture[1]); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[1]->sizeX, TextureImage[1]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[1]->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); } if (TextureImage[1]) { if (TextureImage[1]->data) { free(TextureImage[1]->data); } free(TextureImage[1]); } if (TextureImage[2]=LoadBMP("k3.bmp")) { Status=TRUE; glGenTextures(1, &texture[2]); glBindTexture(GL_TEXTURE_2D, texture[2]); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[2]->sizeX, TextureImage[2]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[2]->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); } if (TextureImage[2]) { if (TextureImage[2]->data) { free(TextureImage[2]->data); } free(TextureImage[2]); } if (TextureImage[3]=LoadBMP("k4.bmp")) { Status=TRUE; glGenTextures(1, &texture[3]); glBindTexture(GL_TEXTURE_2D, texture[3]); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[3]->sizeX, TextureImage[3]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[3]->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); } if (TextureImage[3]) { if (TextureImage[3]->data) { free(TextureImage[3]->data); } free(TextureImage[3]); } if (TextureImage[4]=LoadBMP("k5.bmp")) { Status=TRUE; glGenTextures(1, &texture[4]); glBindTexture(GL_TEXTURE_2D, texture[4]); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[4]->sizeX, TextureImage[4]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[4]->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); } if (TextureImage[4]) { if (TextureImage[4]->data) { free(TextureImage[4]->data); } free(TextureImage[4]); } if (TextureImage[5]=LoadBMP("k6.bmp")) { Status=TRUE; glGenTextures(1, &texture[5]); glBindTexture(GL_TEXTURE_2D, texture[5]); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[5]->sizeX, TextureImage[5]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[5]->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); } if (TextureImage[5]) { if (TextureImage[5]->data) { free(TextureImage[5]->data); } free(TextureImage[5]); } if (TextureImage[6]=LoadBMP("drewno.bmp")) { Status=TRUE; glGenTextures(1, &texture[6]); glBindTexture(GL_TEXTURE_2D, texture[6]); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[6]->sizeX, TextureImage[6]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[6]->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); } if (TextureImage[6]) { if (TextureImage[6]->data) { free(TextureImage[6]->data); } free(TextureImage[6]); } return Status; } GLvoid ReSizeGLScene(GLsizei width, GLsizei height) { if (height==0) { height=1; } glViewport(0,0,width,height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } int InitGL(GLvoid) { if (!LoadGLTextures()) { return FALSE; } glEnable(GL_TEXTURE_2D); glShadeModel(GL_SMOOTH); //Czyszczenie glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); //glFrontFace(GL_CCW); //glEnable(GL_CULL_FACE); //glEnable(GL_LIGHTING); //glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientLight); //glLightfv(GL_LIGHTING, GL_DIFFUSE, ambientLight); //glLightfv(GL_LIGHTING, GL_SPECULAR, specular); //glLightfv(GL_LIGHTING, GL_POSITION, lightPos); //glLightf(GL_LIGHTING, GL_SPOT_CUTOFF, 60.0f); //glEnable(GL_LIGHTING); //glEnable(GL_COLOR_MATERIAL); //glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); //glMaterialfv(GL_FRONT, GL_SPECULAR, specref); //glMateriali(GL_FRONT, GL_SHININESS, 128); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glDepthFunc(GL_LEQUAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); return TRUE; } int DrawGLScene(GLvoid) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glTranslatef(0.0f,0.0f,-5.0f); glPushMatrix(); glRotatef(obroty, 1.0,0.0,0.0); glRotatef(obrot, 0.0,0.5,0.0); glBindTexture(GL_TEXTURE_2D, texture[0]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -1.0f, przod); glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.0f, przod); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 0.0f, przod); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, przod); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[5]); glBegin(GL_QUADS); glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.0f, -1.0f, tyl); glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.0f, 0.0f, tyl); glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 0.0f, tyl); glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, tyl); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[2]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, gora, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, gora, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, gora, -1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, gora, 0.0f); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[3]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, dol, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, dol, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, dol, -1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, dol, 0.0f); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[1]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f( lewa, 0.0f, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( lewa, 0.0f, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( lewa, -1.0f, -1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( lewa, -1.0f, 0.0f); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[4]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f( prawa, 0.0f, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( prawa, 0.0f, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( prawa, -1.0f, -1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( prawa, -1.0f, 0.0f); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[6]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f( -2.0f, -1.0f, +2.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( -2.0f, -1.0f, -3.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 3.0f, -1.0f, -3.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 3.0f, -1.0f, +2.0f); glEnd(); obrot += 0.25; if(obroty <= 30) { obroty+=0.75 ; } return TRUE; } GLvoid KillGLWindow(GLvoid) { if (fullscreen) { ChangeDisplaySettings(NULL,0); ShowCursor(TRUE); } if (hRC) { if (!wglMakeCurrent(NULL,NULL)) { MessageBox(NULL,"Release Of DC And RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); } if (!wglDeleteContext(hRC)) { MessageBox(NULL,"Release Rendering Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); } hRC=NULL; } if (hDC && !ReleaseDC(hWnd,hDC)) { MessageBox(NULL,"Release Device Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); hDC=NULL; } if (hWnd && !DestroyWindow(hWnd)) { MessageBox(NULL,"Could Not Release hWnd.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); hWnd=NULL; } if (!UnregisterClass("OpenGL",hInstance)) { MessageBox(NULL,"Could Not Unregister Class.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); hInstance=NULL; } } BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag) { GLuint PixelFormat; WNDCLASS wc; DWORD dwExStyle; DWORD dwStyle; RECT WindowRect; WindowRect.left=(long)0; WindowRect.right=(long)width; WindowRect.top=(long)0; WindowRect.bottom=(long)height; fullscreen=fullscreenflag; hInstance = GetModuleHandle(NULL); wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wc.lpfnWndProc = (WNDPROC) WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = NULL; wc.lpszMenuName = NULL; wc.lpszClassName = "OpenGL"; if (!RegisterClass(&wc)) { MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; } if (fullscreen) { DEVMODE dmScreenSettings; memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); dmScreenSettings.dmSize=sizeof(dmScreenSettings); dmScreenSettings.dmPelsWidth = width; dmScreenSettings.dmPelsHeight = height; dmScreenSettings.dmBitsPerPel = bits; dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT; if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL) { if (MessageBox(NULL,"The Requested Fullscreen Mode Is Not Supported By\nYour Video Card. Use Windowed Mode Instead?","NeHe GL",MB_YESNO|MB_ICONEXCLAMATION)==IDYES) { fullscreen=FALSE; } else { MessageBox(NULL,"Program Will Now Close.","ERROR",MB_OK|MB_IConstop); return FALSE; } } } if (fullscreen) { dwExStyle=WS_EX_APPWINDOW; dwStyle=WS_POPUP; ShowCursor(FALSE); } else { dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; dwStyle=WS_OVERLAPPEDWINDOW; } AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); if (!(hWnd=CreateWindowEx( dwExStyle, "OpenGL", title, dwStyle | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, WindowRect.right-WindowRect.left, WindowRect.bottom-WindowRect.top, NULL, NULL, hInstance, NULL))) { KillGLWindow(); MessageBox(NULL,"Błąd tworzenia okna","BŁĄD",MB_OK|MB_ICONEXCLAMATION); return FALSE; } static PIXELFORMATDESCRIPTOR pfd= { sizeof(PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, PFD_TYPE_RGBA, bits, 0, 0, 0, 0, 0, 0, 0, 32, // może być 16 0, 0, PFD_MAIN_PLANE, 0, 0, 0, 0 }; if (!(hDC=GetDC(hWnd))) { KillGLWindow(); MessageBox(NULL,"Can't Create A GL Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; } if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd))) { KillGLWindow(); MessageBox(NULL,"Can't Find A Suitable PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; } if(!SetPixelFormat(hDC,PixelFormat,&pfd)) { KillGLWindow(); MessageBox(NULL,"Can't Set The PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; } if (!(hRC=wglCreateContext(hDC))) { KillGLWindow(); MessageBox(NULL,"Can't Create A GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; } if(!wglMakeCurrent(hDC,hRC)) { KillGLWindow(); MessageBox(NULL,"Can't Activate The GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; } ShowWindow(hWnd,SW_SHOW); SetForegroundWindow(hWnd); SetFocus(hWnd); ReSizeGLScene(width, height); if (!InitGL()) { KillGLWindow(); MessageBox(NULL,"Błąd inicjalizacji. Pewnie brak textur.","Błąd",MB_OK|MB_ICONEXCLAMATION); return FALSE; } return TRUE; } LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_ACTIVATE: { if (!HIWORD(wParam)) { active=TRUE; } else { active=FALSE; } return 0; } case WM_SYSCOMMAND: { switch (wParam) { case SC_SCREENSAVE: case SC_MONITORPOWER: return 0; } break; } case WM_CLOSE: { PostQuitMessage(0); return 0; } case WM_KEYDOWN: { keys[wParam] = TRUE; return 0; } case WM_KEYUP: { keys[wParam] = FALSE; return 0; } case WM_SIZE: { ReSizeGLScene(LOWORD(lParam),HIWORD(lParam)); return 0; } } return DefWindowProc(hWnd,uMsg,wParam,lParam); } int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MSG msg; BOOL done=FALSE; if (MessageBox(NULL,"Czy chcesz uruchomić w pełnym oknie?", "Pełne okno?",MB_YESNO|MB_ICONQUESTION)==IDNO) { fullscreen=FALSE; } if (!CreateGLWindow("Kostka",1024,768,32,fullscreen)) { return 0; } while(!done) { if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { if (msg.message==WM_QUIT) { done=TRUE; } else { TranslateMessage(&msg); DispatchMessage(&msg); } } else { if ((active && !DrawGLScene()) || keys[VK_ESCAPE]) { done=TRUE; } else { SwapBuffers(hDC); } } if (keys[VK_F1]) { keys[VK_F1]=FALSE; KillGLWindow(); fullscreen=!fullscreen; if (!CreateGLWindow("Kostka",1024,768,32,fullscreen)) { return 0; } } // } } KillGLWindow(); return (msg.wParam); }
Użytkownik Kubek_pl edytował ten post 07 czerwiec 2005, 17:58

...


Widać jak nic, przede wszystkim po ew. komunikatach o błędach :P

Ok, bazowałem na Nehe( ale troche pozmieniałem :) )
Mój kod źródłowy wygląda tak
#include <windows.h> #include <stdio.h> #include <gl\gl.h> #include <gl\glu.h> #include <gl\glaux.h> HDC hDC=NULL; HGLRC hRC=NULL; HWND hWnd=NULL; HINSTANCE hInstance; bool keys[256]; bool active=TRUE; bool fullscreen=TRUE; GLuint texture[7]; float obrot; float obroty; float przod = 0.0f; float tyl = -1.0f; float lewa; float prawa; float gora = 0.0f; float dol = -1.0f; bool koniec; bool animacja; bool done=FALSE; //GLfloat lightPos[] = { 0.0f, 0.0f, 75.0f, 1.0f}; //GLfloat specular[] = { 1.0f, 1.0f, 1.0f, 1.0f}; //GLfloat specref[] = { 1.0f, 1.0f, 1.0f, 1.0f}; //GLfloat ambientLight[] = { 0.5f, 0.5f, 0.5f, 1.0f}; //GLfloat spotDir[] = { 0.0f, 0.0f, -1.0f}; LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); AUX_RGBImageRec *LoadBMP(char *Filename) { FILE *File=NULL; if (!Filename) { return NULL; } File=fopen(Filename,"r"); if (File) { fclose(File); return auxDIBImageLoad(Filename); } return NULL; } int LoadGLTextures() { int Status=FALSE; AUX_RGBImageRec *TextureImage[7]; memset(TextureImage,0,sizeof(void *)*1); if (TextureImage[0]=LoadBMP("k1.bmp")) { Status=TRUE; glGenTextures(1, &texture[0]); glBindTexture(GL_TEXTURE_2D, texture[0]); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); } if (TextureImage[0]) { if (TextureImage[0]->data) { free(TextureImage[0]->data); } free(TextureImage[0]); } if (TextureImage[1]=LoadBMP("k2.bmp")) { Status=TRUE; glGenTextures(1, &texture[1]); glBindTexture(GL_TEXTURE_2D, texture[1]); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[1]->sizeX, TextureImage[1]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[1]->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); } if (TextureImage[1]) { if (TextureImage[1]->data) { free(TextureImage[1]->data); } free(TextureImage[1]); } if (TextureImage[2]=LoadBMP("k3.bmp")) { Status=TRUE; glGenTextures(1, &texture[2]); glBindTexture(GL_TEXTURE_2D, texture[2]); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[2]->sizeX, TextureImage[2]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[2]->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); } if (TextureImage[2]) { if (TextureImage[2]->data) { free(TextureImage[2]->data); } free(TextureImage[2]); } if (TextureImage[3]=LoadBMP("k4.bmp")) { Status=TRUE; glGenTextures(1, &texture[3]); glBindTexture(GL_TEXTURE_2D, texture[3]); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[3]->sizeX, TextureImage[3]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[3]->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); } if (TextureImage[3]) { if (TextureImage[3]->data) { free(TextureImage[3]->data); } free(TextureImage[3]); } if (TextureImage[4]=LoadBMP("k5.bmp")) { Status=TRUE; glGenTextures(1, &texture[4]); glBindTexture(GL_TEXTURE_2D, texture[4]); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[4]->sizeX, TextureImage[4]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[4]->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); } if (TextureImage[4]) { if (TextureImage[4]->data) { free(TextureImage[4]->data); } free(TextureImage[4]); } if (TextureImage[5]=LoadBMP("k6.bmp")) { Status=TRUE; glGenTextures(1, &texture[5]); glBindTexture(GL_TEXTURE_2D, texture[5]); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[5]->sizeX, TextureImage[5]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[5]->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); } if (TextureImage[5]) { if (TextureImage[5]->data) { free(TextureImage[5]->data); } free(TextureImage[5]); } if (TextureImage[6]=LoadBMP("drewno.bmp")) { Status=TRUE; glGenTextures(1, &texture[6]); glBindTexture(GL_TEXTURE_2D, texture[6]); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[6]->sizeX, TextureImage[6]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[6]->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); } if (TextureImage[6]) { if (TextureImage[6]->data) { free(TextureImage[6]->data); } free(TextureImage[6]); } return Status; } GLvoid ReSizeGLScene(GLsizei width, GLsizei height) { if (height==0) { height=1; } glViewport(0,0,width,height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } int InitGL(GLvoid) { if (!LoadGLTextures()) { return FALSE; } glEnable(GL_TEXTURE_2D); glShadeModel(GL_SMOOTH); //Czyszczenie glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); //glFrontFace(GL_CCW); //glEnable(GL_CULL_FACE); //glEnable(GL_LIGHTING); //glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientLight); //glLightfv(GL_LIGHTING, GL_DIFFUSE, ambientLight); //glLightfv(GL_LIGHTING, GL_SPECULAR, specular); //glLightfv(GL_LIGHTING, GL_POSITION, lightPos); //glLightf(GL_LIGHTING, GL_SPOT_CUTOFF, 60.0f); //glEnable(GL_LIGHTING); //glEnable(GL_COLOR_MATERIAL); //glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); //glMaterialfv(GL_FRONT, GL_SPECULAR, specref); //glMateriali(GL_FRONT, GL_SHININESS, 128); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glDepthFunc(GL_LEQUAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); return TRUE; } int DrawGLScene(GLvoid) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glTranslatef(0.0f,0.0f,-5.0f); glPushMatrix(); glRotatef(obroty, 1.0,0.0,0.0); glRotatef(obrot, 0.0,0.5,0.0); glBindTexture(GL_TEXTURE_2D, texture[0]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -1.0f, przod); glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.0f, przod); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 0.0f, przod); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, przod); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[5]); glBegin(GL_QUADS); glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.0f, -1.0f, tyl); glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.0f, 0.0f, tyl); glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 0.0f, tyl); glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, tyl); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[2]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, gora, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, gora, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, gora, -1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, gora, 0.0f); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[3]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, dol, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, dol, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, dol, -1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, dol, 0.0f); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[1]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f( lewa, 0.0f, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( lewa, 0.0f, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( lewa, -1.0f, -1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( lewa, -1.0f, 0.0f); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[4]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f( prawa, 0.0f, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( prawa, 0.0f, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( prawa, -1.0f, -1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( prawa, -1.0f, 0.0f); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[6]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f( -2.0f, -1.0f, +2.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( -2.0f, -1.0f, -3.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 3.0f, -1.0f, -3.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 3.0f, -1.0f, +2.0f); glEnd(); if(koniec == TRUE) { if(przod < 2,0)//tutaj ograwniczenia ruchu { przod += 0.05f; tyl -= 0.05f; gora += 0.05f; dol -= 0.05f; lewa -=0.05f; prawa +=0.05f; } else { if(animacja == TRUE) { done = TRUE; } } } obrot += 0.25; if(obroty <= 30) { obroty+=0.75 ; } return TRUE; } GLvoid KillGLWindow(GLvoid) { if (fullscreen) { ChangeDisplaySettings(NULL,0); ShowCursor(TRUE); } if (hRC) { if (!wglMakeCurrent(NULL,NULL)) { MessageBox(NULL,"Release Of DC And RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); } if (!wglDeleteContext(hRC)) { MessageBox(NULL,"Release Rendering Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); } hRC=NULL; } if (hDC && !ReleaseDC(hWnd,hDC)) { MessageBox(NULL,"Release Device Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); hDC=NULL; } if (hWnd && !DestroyWindow(hWnd)) { MessageBox(NULL,"Could Not Release hWnd.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); hWnd=NULL; } if (!UnregisterClass("OpenGL",hInstance)) { MessageBox(NULL,"Could Not Unregister Class.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); hInstance=NULL; } } BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag) { GLuint PixelFormat; WNDCLASS wc; DWORD dwExStyle; DWORD dwStyle; RECT WindowRect; WindowRect.left=(long)0; WindowRect.right=(long)width; WindowRect.top=(long)0; WindowRect.bottom=(long)height; fullscreen=fullscreenflag; hInstance = GetModuleHandle(NULL); wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wc.lpfnWndProc = (WNDPROC) WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = NULL; wc.lpszMenuName = NULL; wc.lpszClassName = "OpenGL"; if (!RegisterClass(&wc)) { MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; } if (fullscreen) { DEVMODE dmScreenSettings; memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); dmScreenSettings.dmSize=sizeof(dmScreenSettings); dmScreenSettings.dmPelsWidth = width; dmScreenSettings.dmPelsHeight = height; dmScreenSettings.dmBitsPerPel = bits; dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT; if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL) { if (MessageBox(NULL,"The Requested Fullscreen Mode Is Not Supported By\nYour Video Card. Use Windowed Mode Instead?","NeHe GL",MB_YESNO|MB_ICONEXCLAMATION)==IDYES) { fullscreen=FALSE; } else { MessageBox(NULL,"Program Will Now Close.","ERROR",MB_OK|MB_IConstop); return FALSE; } } } if (fullscreen) { dwExStyle=WS_EX_APPWINDOW; dwStyle=WS_POPUP; ShowCursor(FALSE); } else { dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; dwStyle=WS_OVERLAPPEDWINDOW; } AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); if (!(hWnd=CreateWindowEx( dwExStyle, "OpenGL", title, dwStyle | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, WindowRect.right-WindowRect.left, WindowRect.bottom-WindowRect.top, NULL, NULL, hInstance, NULL))) { KillGLWindow(); MessageBox(NULL,"Błąd tworzenia okna","BŁĄD",MB_OK|MB_ICONEXCLAMATION); return FALSE; } static PIXELFORMATDESCRIPTOR pfd= { sizeof(PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, PFD_TYPE_RGBA, bits, 0, 0, 0, 0, 0, 0, 0, 32, // może być 16 0, 0, PFD_MAIN_PLANE, 0, 0, 0, 0 }; if (!(hDC=GetDC(hWnd))) { KillGLWindow(); MessageBox(NULL,"Can't Create A GL Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; } if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd))) { KillGLWindow(); MessageBox(NULL,"Can't Find A Suitable PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; } if(!SetPixelFormat(hDC,PixelFormat,&pfd)) { KillGLWindow(); MessageBox(NULL,"Can't Set The PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; } if (!(hRC=wglCreateContext(hDC))) { KillGLWindow(); MessageBox(NULL,"Can't Create A GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; } if(!wglMakeCurrent(hDC,hRC)) { KillGLWindow(); MessageBox(NULL,"Can't Activate The GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; } ShowWindow(hWnd,SW_SHOW); SetForegroundWindow(hWnd); SetFocus(hWnd); ReSizeGLScene(width, height); if (!InitGL()) { KillGLWindow(); MessageBox(NULL,"Błąd inicjalizacji. Pewnie brak textur.","Błąd",MB_OK|MB_ICONEXCLAMATION); return FALSE; } return TRUE; } LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_ACTIVATE: { if (!HIWORD(wParam)) { active=TRUE; } else { active=FALSE; } return 0; } case WM_SYSCOMMAND: { switch (wParam) { case SC_SCREENSAVE: case SC_MONITORPOWER: return 0; } break; } case WM_CLOSE: { PostQuitMessage(0); return 0; } case WM_KEYDOWN: { keys[wParam] = TRUE; return 0; } case WM_KEYUP: { keys[wParam] = FALSE; return 0; } case WM_SIZE: { ReSizeGLScene(LOWORD(lParam),HIWORD(lParam)); return 0; } } return DefWindowProc(hWnd,uMsg,wParam,lParam); } int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MSG msg; //BOOL done=FALSE; if (MessageBox(NULL,"Czy chcesz uruchomić w pełnym oknie?", "Pełne okno?",MB_YESNO|MB_ICONQUESTION)==IDNO) { fullscreen=FALSE; } if (!CreateGLWindow("Kostka",1024,768,32,fullscreen)) { return 0; } while(!done) { if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { if (msg.message==WM_QUIT) { done=TRUE; } else { TranslateMessage(&msg); DispatchMessage(&msg); } } else { if ((active && !DrawGLScene())) { done=TRUE; } else { SwapBuffers(hDC); } if (keys[VK_ESCAPE]) { koniec=TRUE; keys[VK_ESCAPE] = FALSE; } } if (keys[VK_F1]) { keys[VK_F1]=FALSE; KillGLWindow(); fullscreen=!fullscreen; if (!CreateGLWindow("Kostka",1024,768,32,fullscreen)) { return 0; } } // } } KillGLWindow(); return (msg.wParam); }
PS.Aplikacja nie wyłancza sie. Nie ma animacji.
Za chwile spróbuje wedłóg twojego sposobu(Real_Noname)
Użytkownik Kubek_pl edytował ten post 09 czerwiec 2005, 20:07
Nowy kod ale bez efektów
#include <windows.h> #include <stdio.h> #include <gl\gl.h> #include <gl\glu.h> #include <gl\glaux.h> HDC hDC=NULL; HGLRC hRC=NULL; HWND hWnd=NULL; HINSTANCE hInstance; bool keys[256]; bool active=TRUE; bool fullscreen=TRUE; GLuint texture[7]; float obrot; float obroty; float przod = 0.0f; float tyl = -1.0f; float lewa; float prawa; float gora = 0.0f; float dol = -1.0f; bool koniec; bool animacja; bool done=FALSE; bool poczatek=FALSE; //GLfloat lightPos[] = { 0.0f, 0.0f, 75.0f, 1.0f}; //GLfloat specular[] = { 1.0f, 1.0f, 1.0f, 1.0f}; //GLfloat specref[] = { 1.0f, 1.0f, 1.0f, 1.0f}; //GLfloat ambientLight[] = { 0.5f, 0.5f, 0.5f, 1.0f}; //GLfloat spotDir[] = { 0.0f, 0.0f, -1.0f}; LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); AUX_RGBImageRec *LoadBMP(char *Filename) { FILE *File=NULL; if (!Filename) { return NULL; } File=fopen(Filename,"r"); if (File) { fclose(File); return auxDIBImageLoad(Filename); } return NULL; } int LoadGLTextures() { int Status=FALSE; AUX_RGBImageRec *TextureImage[7]; memset(TextureImage,0,sizeof(void *)*1); if (TextureImage[0]=LoadBMP("k1.bmp")) { Status=TRUE; glGenTextures(1, &texture[0]); glBindTexture(GL_TEXTURE_2D, texture[0]); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); } if (TextureImage[0]) { if (TextureImage[0]->data) { free(TextureImage[0]->data); } free(TextureImage[0]); } if (TextureImage[1]=LoadBMP("k2.bmp")) { Status=TRUE; glGenTextures(1, &texture[1]); glBindTexture(GL_TEXTURE_2D, texture[1]); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[1]->sizeX, TextureImage[1]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[1]->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); } if (TextureImage[1]) { if (TextureImage[1]->data) { free(TextureImage[1]->data); } free(TextureImage[1]); } if (TextureImage[2]=LoadBMP("k3.bmp")) { Status=TRUE; glGenTextures(1, &texture[2]); glBindTexture(GL_TEXTURE_2D, texture[2]); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[2]->sizeX, TextureImage[2]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[2]->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); } if (TextureImage[2]) { if (TextureImage[2]->data) { free(TextureImage[2]->data); } free(TextureImage[2]); } if (TextureImage[3]=LoadBMP("k4.bmp")) { Status=TRUE; glGenTextures(1, &texture[3]); glBindTexture(GL_TEXTURE_2D, texture[3]); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[3]->sizeX, TextureImage[3]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[3]->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); } if (TextureImage[3]) { if (TextureImage[3]->data) { free(TextureImage[3]->data); } free(TextureImage[3]); } if (TextureImage[4]=LoadBMP("k5.bmp")) { Status=TRUE; glGenTextures(1, &texture[4]); glBindTexture(GL_TEXTURE_2D, texture[4]); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[4]->sizeX, TextureImage[4]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[4]->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); } if (TextureImage[4]) { if (TextureImage[4]->data) { free(TextureImage[4]->data); } free(TextureImage[4]); } if (TextureImage[5]=LoadBMP("k6.bmp")) { Status=TRUE; glGenTextures(1, &texture[5]); glBindTexture(GL_TEXTURE_2D, texture[5]); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[5]->sizeX, TextureImage[5]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[5]->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); } if (TextureImage[5]) { if (TextureImage[5]->data) { free(TextureImage[5]->data); } free(TextureImage[5]); } if (TextureImage[6]=LoadBMP("drewno.bmp")) { Status=TRUE; glGenTextures(1, &texture[6]); glBindTexture(GL_TEXTURE_2D, texture[6]); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[6]->sizeX, TextureImage[6]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[6]->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); } if (TextureImage[6]) { if (TextureImage[6]->data) { free(TextureImage[6]->data); } free(TextureImage[6]); } return Status; } GLvoid ReSizeGLScene(GLsizei width, GLsizei height) { if (height==0) { height=1; } glViewport(0,0,width,height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } int InitGL(GLvoid) { if (!LoadGLTextures()) { return FALSE; } glEnable(GL_TEXTURE_2D); glShadeModel(GL_SMOOTH); //Czyszczenie glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); //glFrontFace(GL_CCW); //glEnable(GL_CULL_FACE); //glEnable(GL_LIGHTING); //glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientLight); //glLightfv(GL_LIGHTING, GL_DIFFUSE, ambientLight); //glLightfv(GL_LIGHTING, GL_SPECULAR, specular); //glLightfv(GL_LIGHTING, GL_POSITION, lightPos); //glLightf(GL_LIGHTING, GL_SPOT_CUTOFF, 60.0f); //glEnable(GL_LIGHTING); //glEnable(GL_COLOR_MATERIAL); //glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); //glMaterialfv(GL_FRONT, GL_SPECULAR, specref); //glMateriali(GL_FRONT, GL_SHININESS, 128); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glDepthFunc(GL_LEQUAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); return TRUE; } int DrawGLScene(GLvoid) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glTranslatef(0.0f,0.0f,-5.0f); glPushMatrix(); glRotatef(obroty, 1.0,0.0,0.0); glRotatef(obrot, 0.0,0.5,0.0); if(koniec == TRUE) { if(przod < 2,0) { for(float i=0.0; i == przod; i += 0.05f) { przod += 0.05f; tyl -= 0.05f; gora += 0.05f; dol -= 0.05f; lewa -=0.05f; prawa +=0.05f; glBindTexture(GL_TEXTURE_2D, texture[0]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -1.0f, przod); glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.0f, przod); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 0.0f, przod); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, przod); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[5]); glBegin(GL_QUADS); glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.0f, -1.0f, tyl); glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.0f, 0.0f, tyl); glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 0.0f, tyl); glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, tyl); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[2]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, gora, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, gora, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, gora, -1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, gora, 0.0f); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[3]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, dol, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, dol, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, dol, -1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, dol, 0.0f); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[1]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f( lewa, 0.0f, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( lewa, 0.0f, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( lewa, -1.0f, -1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( lewa, -1.0f, 0.0f); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[4]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f( prawa, 0.0f, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( prawa, 0.0f, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( prawa, -1.0f, -1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( prawa, -1.0f, 0.0f); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[6]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f( -2.0f, -1.0f, +2.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( -2.0f, -1.0f, -3.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 3.0f, -1.0f, -3.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 3.0f, -1.0f, +2.0f); glEnd(); } } } if(przod == 0.0f) { glBindTexture(GL_TEXTURE_2D, texture[0]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -1.0f, przod); glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.0f, przod); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 0.0f, przod); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, przod); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[5]); glBegin(GL_QUADS); glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.0f, -1.0f, tyl); glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.0f, 0.0f, tyl); glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 0.0f, tyl); glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, tyl); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[2]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, gora, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, gora, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, gora, -1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, gora, 0.0f); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[3]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, dol, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, dol, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, dol, -1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, dol, 0.0f); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[1]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f( lewa, 0.0f, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( lewa, 0.0f, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( lewa, -1.0f, -1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( lewa, -1.0f, 0.0f); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[4]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f( prawa, 0.0f, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( prawa, 0.0f, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( prawa, -1.0f, -1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( prawa, -1.0f, 0.0f); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[6]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f( -2.0f, -1.0f, +2.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( -2.0f, -1.0f, -3.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 3.0f, -1.0f, -3.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 3.0f, -1.0f, +2.0f); glEnd(); } if(animacja == TRUE) { done = TRUE; } obrot += 0.25; if(obroty <= 30) { obroty+=0.75 ; } return TRUE; } GLvoid KillGLWindow(GLvoid) { if (fullscreen) { ChangeDisplaySettings(NULL,0); ShowCursor(TRUE); } if (hRC) { if (!wglMakeCurrent(NULL,NULL)) { MessageBox(NULL,"Release Of DC And RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); } if (!wglDeleteContext(hRC)) { MessageBox(NULL,"Release Rendering Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); } hRC=NULL; } if (hDC && !ReleaseDC(hWnd,hDC)) { MessageBox(NULL,"Release Device Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); hDC=NULL; } if (hWnd && !DestroyWindow(hWnd)) { MessageBox(NULL,"Could Not Release hWnd.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); hWnd=NULL; } if (!UnregisterClass("OpenGL",hInstance)) { MessageBox(NULL,"Could Not Unregister Class.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); hInstance=NULL; } } BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag) { GLuint PixelFormat; WNDCLASS wc; DWORD dwExStyle; DWORD dwStyle; RECT WindowRect; WindowRect.left=(long)0; WindowRect.right=(long)width; WindowRect.top=(long)0; WindowRect.bottom=(long)height; fullscreen=fullscreenflag; hInstance = GetModuleHandle(NULL); wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wc.lpfnWndProc = (WNDPROC) WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = NULL; wc.lpszMenuName = NULL; wc.lpszClassName = "OpenGL"; if (!RegisterClass(&wc)) { MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; } if (fullscreen) { DEVMODE dmScreenSettings; memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); dmScreenSettings.dmSize=sizeof(dmScreenSettings); dmScreenSettings.dmPelsWidth = width; dmScreenSettings.dmPelsHeight = height; dmScreenSettings.dmBitsPerPel = bits; dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT; if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL) { if (MessageBox(NULL,"The Requested Fullscreen Mode Is Not Supported By\nYour Video Card. Use Windowed Mode Instead?","NeHe GL",MB_YESNO|MB_ICONEXCLAMATION)==IDYES) { fullscreen=FALSE; } else { MessageBox(NULL,"Program Will Now Close.","ERROR",MB_OK|MB_IConstop); return FALSE; } } } if (fullscreen) { dwExStyle=WS_EX_APPWINDOW; dwStyle=WS_POPUP; ShowCursor(FALSE); } else { dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; dwStyle=WS_OVERLAPPEDWINDOW; } AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); if (!(hWnd=CreateWindowEx( dwExStyle, "OpenGL", title, dwStyle | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, WindowRect.right-WindowRect.left, WindowRect.bottom-WindowRect.top, NULL, NULL, hInstance, NULL))) { KillGLWindow(); MessageBox(NULL,"Błąd tworzenia okna","BŁĄD",MB_OK|MB_ICONEXCLAMATION); return FALSE; } static PIXELFORMATDESCRIPTOR pfd= { sizeof(PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, PFD_TYPE_RGBA, bits, 0, 0, 0, 0, 0, 0, 0, 32, // może być 16 0, 0, PFD_MAIN_PLANE, 0, 0, 0, 0 }; if (!(hDC=GetDC(hWnd))) { KillGLWindow(); MessageBox(NULL,"Can't Create A GL Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; } if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd))) { KillGLWindow(); MessageBox(NULL,"Can't Find A Suitable PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; } if(!SetPixelFormat(hDC,PixelFormat,&pfd)) { KillGLWindow(); MessageBox(NULL,"Can't Set The PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; } if (!(hRC=wglCreateContext(hDC))) { KillGLWindow(); MessageBox(NULL,"Can't Create A GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; } if(!wglMakeCurrent(hDC,hRC)) { KillGLWindow(); MessageBox(NULL,"Can't Activate The GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; } ShowWindow(hWnd,SW_SHOW); SetForegroundWindow(hWnd); SetFocus(hWnd); ReSizeGLScene(width, height); if (!InitGL()) { KillGLWindow(); MessageBox(NULL,"Błąd inicjalizacji. Pewnie brak textur.","Błąd",MB_OK|MB_ICONEXCLAMATION); return FALSE; } return TRUE; } LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_ACTIVATE: { if (!HIWORD(wParam)) { active=TRUE; } else { active=FALSE; } return 0; } case WM_SYSCOMMAND: { switch (wParam) { case SC_SCREENSAVE: case SC_MONITORPOWER: return 0; } break; } case WM_CLOSE: { PostQuitMessage(0); return 0; } case WM_KEYDOWN: { keys[wParam] = TRUE; return 0; } case WM_KEYUP: { keys[wParam] = FALSE; return 0; } case WM_SIZE: { ReSizeGLScene(LOWORD(lParam),HIWORD(lParam)); return 0; } } return DefWindowProc(hWnd,uMsg,wParam,lParam); } int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MSG msg; BOOL done=FALSE; if (MessageBox(NULL,"Czy chcesz uruchomić w pełnym oknie?", "Pełne okno?",MB_YESNO|MB_ICONQUESTION)==IDNO) { fullscreen=FALSE; } if (!CreateGLWindow("Kostka",1024,768,32,fullscreen)) { return 0; } while(!done) { if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { if (msg.message==WM_QUIT) { done=TRUE; } else { TranslateMessage(&msg); DispatchMessage(&msg); } } else { if ((active && !DrawGLScene())) { done=TRUE; } else { SwapBuffers(hDC); } if (keys[VK_ESCAPE]) { koniec=TRUE; keys[VK_ESCAPE] = FALSE; } } if (keys[VK_F1]) { keys[VK_F1]=FALSE; KillGLWindow(); fullscreen=!fullscreen; if (!CreateGLWindow("Kostka",1024,768,32,fullscreen)) { return 0; } } // } } KillGLWindow(); return (msg.wParam); }


...

Real_Noname, glupoty tym razem napisales :) tzn, stos macierzy w GLu nie ma zadnego zwiazku ze stosem aplikacji i nic by sie nie stalo, OpenGL jedynie w przypadku przepelnienia ustawia flage bledu GL_STACK_OVERFLOW i tyle ;>


Real_Noname, glupoty tym razem napisales :) tzn, stos macierzy w GLu nie ma zadnego zwiazku ze stosem aplikacji i nic by sie nie stalo, OpenGL jedynie w przypadku przepelnienia ustawia flage bledu GL_STACK_OVERFLOW i tyle ;>

no tak, ale mi tylko chodzilo o to co napisal Real_Noname, nie chcialem nikogo pojezdzac i tak dalej, tylko wyprowadzic z bledu. jesli zostalem zle zrozumiany to sorry, nie lubie poprawiac madrych ludzi.

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • zsf.htw.pl
  •