#include "COpenGL.h"
LRESULT CALLBACK StaticWndProc (HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) //functie statica ce intoarce functia WndProc daca pointerul nu este null.
{
COpenGL* x = NULL;
x = (COpenGL*) GetWindowLong(hWnd, GWL_USERDATA);
if (x) {
return x->WndProc(hWnd,uMsg,wParam,lParam);
}else{
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
}
LRESULT CALLBACK COpenGL::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);
}
COpenGL::COpenGL(){
hRC=NULL;
hDC=NULL;
hWnd=NULL;
active=TRUE;
fullscreen=TRUE;
rtri=0.0f;
rquad=0.0f;
for (int i=0;i<256;i++)
keys[i]=false;
}
GLvoid COpenGL::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 COpenGL::InitGL(GLvoid) // All Setup For OpenGL Goes Here
{
glShadeModel(GL_SMOOTH); // Enables Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Test To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
return TRUE; // Initialization Went OK
}
GLvoid COpenGL::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,"Release Of DC And RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
}
if (!wglDeleteContext(hRC)) // Are We Able To Delete The RC?
{
MessageBox(NULL,"Release Rendering Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
}
hRC=NULL; // Set RC To NULL
}
if (hDC && !ReleaseDC(hWnd,hDC)) // Are We Able To Release The DC
{
MessageBox(NULL,"Release Device Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
hDC=NULL; // Set DC To NULL
}
if (hWnd && !DestroyWindow(hWnd)) // Are We Able To Destroy The Window?
{
MessageBox(NULL,"Could Not Release hWnd.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
hWnd=NULL; // Set hWnd To NULL
}
if (!UnregisterClass("OpenGL",hInstance)) // Are We Able To Unregister Class
{
MessageBox(NULL,"Could Not Unregister Class.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
hInstance=NULL; // Set hInstance To NULL
}
}
void drawTriangle (GLfloat x1, GLfloat y1,GLfloat z1, GLfloat x2, GLfloat y2, GLfloat z2, GLfloat x3, GLfloat y3, GLfloat z3)
{
glBegin (GL_TRIANGLES);
glVertex3f (x1, y1, z1);
glVertex3f (x2, y2, z2);
glVertex3f (x3, y3, z3);
glEnd ();
}
void drawViewVolume (GLfloat x1, GLfloat x2, GLfloat y1,GLfloat y2, GLfloat z1, GLfloat z2)
{
glColor3f (1.0, 1.0, 1.0);
glBegin (GL_LINE_LOOP);
glVertex3f (x1, y1, -z1);
glVertex3f (x2, y1, -z1);
glVertex3f (x2, y2, -z1);
glVertex3f (x1, y2, -z1);
glEnd ();
glBegin (GL_LINE_LOOP);
glVertex3f (x1, y1, -z2);
glVertex3f (x2, y1, -z2);
glVertex3f (x2, y2, -z2);
glVertex3f (x1, y2, -z2);
glEnd ();
glBegin (GL_LINES); /* 4 lines */
glVertex3f (x1, y1, -z1);
glVertex3f (x1, y1, -z2);
glVertex3f (x1, y2, -z1);
glVertex3f (x1, y2, -z2);
glVertex3f (x2, y1, -z1);
glVertex3f (x2, y1, -z2);
glVertex3f (x2, y2, -z1);
glVertex3f (x2, y2, -z2);
glEnd ();
}
//void functie(GLvoid){
//
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
// glLoadIdentity(); // Reset The View
// gluPerspective (40.0, 4.0/3.0, 0.01, 100.0); //NEW
// glMatrixMode (GL_MODELVIEW); //NEW
// glTranslatef(-1.5f,0.0f,-6.0f); // Move Into The Screen And Left
//
// gluLookAt (7.5, 7.5, 2.5, 2.5, 2.5, -5.0, 0.0, 1.0, 0.0);
// glColor3f (0.0, 1.0, 0.0); /* green triangle */
// drawTriangle (2.0, 2.0, 3.0, 2.0, 2.5, 3.0, -5.0);
// glColor3f (1.0, 0.0, 0.0); /* red triangle */
// drawTriangle (2.0, 7.0, 3.0, 7.0, 2.5, 8.0, -5.0);
// glColor3f (1.0, 1.0, 0.0); /* yellow triangles */
// drawTriangle (2.0, 2.0, 3.0, 2.0, 2.5, 3.0, 0.0);
// drawTriangle (2.0, 2.0, 3.0, 2.0, 2.5, 3.0, -10.0);
// drawViewVolume (0.0, 5.0, 0.0, 5.0, 0.0, 10.0);
//}
int COpenGL::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
glTranslatef(-1.5f,0.0f,-6.0f); // Move Into The Screen And Left
glRotatef(rtri,1.0f,1.0f,1.0f); // Rotate The Triangle On The Y axis ( NEW )
glBegin(GL_TRIANGLE_FAN); // draw triangle
glColor3f(1.0f,0.0f,0.0f); // set color to red
glVertex3f( 0.0f, 0.3f, 0.0f);
glColor3f(0.0f,1.0f,0.0f); // set color to green
glVertex3f(-0.5f, -0.5f, 0.5f);
glColor3f(1.0f,1.0f,0.0f); // set color to yellow
glVertex3f( 0.5f, -0.5f, 0.5f);
glColor3f(0.0f,0.0f,1.0f); // set color to blue
glVertex3f( 0.5f, -0.5f, -0.5f);
glColor3f(1.0f,1.0f,1.0f); // set color to white
glVertex3f( -0.5f, -0.5f, -0.5f);
glColor3f(0.0f,1.0f,0.0f); // set color to green
glVertex3f(-0.5f, -0.5f, 0.5f);
glEnd();
// glPushMatrix();
没有合适的资源?快使用搜索试试~ 我知道了~
OpenGL.zip_objects
共29个文件
bmp:4个
bat:3个
obj:2个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 2 浏览量
2022-09-20
19:19:27
上传
评论
收藏 5.83MB ZIP 举报
温馨提示
Open GL example - simple creation of 3D objects
资源推荐
资源详情
资源评论
收起资源包目录
OpenGL.zip (29个子文件)
Tema_21
Tema_21.sln 887B
test.txt 19KB
Tema_21.ncb 13.56MB
Tema_21
COpenGLMain.cpp 7KB
Crate.bmp 192KB
Tema#2 - Pope Ruxandra,342A2.zip 7KB
COpenGL.cpp 27KB
coffee-mug.bmp 420KB
coffeemm.bmp 485KB
COpenGL.h 3KB
World.txt 3KB
Tema_21.vcproj 4KB
coffee-mug.jpg 58KB
Tema_21.vcproj.Rux-NB.Rux.user 1KB
Debug
BAT00000426964888.bat 75B
BAT00001716446696.bat 75B
BuildLog.htm 7KB
BAT00003216004220.bat 75B
vc90.pdb 124KB
Tema_21.exe.intermediate.manifest 621B
vc90.idb 435KB
mt.dep 66B
COpenGL.obj 67KB
COpenGLMain.obj 28KB
wallofbooks.bmp 703KB
Debug
Tema_21.pdb 467KB
Tema_21.exe 48KB
Tema_21.ilk 477KB
Tema_21.suo 42KB
共 29 条
- 1
资源评论
朱moyimi
- 粉丝: 65
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功