Może wkleje swój kod:
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <stdio.h>
char className[] = {"ogl_app_class"};
char wndCaption[] = {"ogl_app"};
LRESULT CALLBACK WndMsgProc (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
int screen_width = 1000;
int screen_height = 600;
int screen_bits = 16;
int screen_frequency = 30;
BOOL full_screen = TRUE;
HGLRC hRC;
HDC hDC;
void SetupPixelFormat (HDC hDC);
void StartWGL(HWND hWnd);
void StopWGL();
void GetFullScreen();
void SetupRC();
void ChangeSize(int width, int height);
void Render();
void sciana();
void test(int xPos);
void ProcesSelection(int xPos, int yPos,int width, int height);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) {
WNDCLASSEX wc;
HWND hWnd;
MSG Msg;
int style;
ZeroMemory(&wc, sizeof(WNDCLASSEX));
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.hInstance = hInstance;
wc.lpfnWndProc = WndMsgProc;
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wc.hIconSm = wc.hIcon;
wc.lpszClassName = className;
wc.lpszMenuName = NULL;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
RegisterClassEx(&wc);
if (full_screen)
{
style = WS_POPUP;
}
else {
style = WS_OVERLAPPEDWINDOW;
}
hWnd = CreateWindowEx(0, className, wndCaption,style, 0, 0, screen_width, screen_height, NULL, NULL, hInstance, NULL);
ShowWindow(hWnd, nShowCmd);
while (1) {
if (PeekMessage(&Msg,0,0,0,PM_REMOVE )) {
if (Msg.message == WM_QUIT) {
break;
}
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
else {
Render();
SwapBuffers(hDC);
}
}
return 0;
}
LRESULT CALLBACK WndMsgProc (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) {
switch (Msg)
{
case WM_CREATE:
StartWGL(hWnd);
SetupRC();
break;
case WM_DESTROY:
StopWGL();
PostQuitMessage(0);
break;
case WM_SIZE:
{
int width = LOWORD(lParam);
int height = HIWORD(lParam);
ChangeSize(width, height);
}
break;
case WM_LBUTTONDOWN:
{
int xPos = LOWORD(lParam);
int yPos = HIWORD(lParam);
//ProcesSelection(xPos, yPos, screen_width, screen_height);
float szer = 2.9;
test(2.9);
break;
}
}
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
void SetupPixelFormat(HDC hDC)
{
int pixelFormat;
static PIXELFORMATDESCRIPTOR pfd =
{
sizeof (PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, PFD_TYPE_RGBA,
32,
0,0,0,0,0,0,
0,
0,
0,
0,0,0,0,
16,
0,
0,
PFD_MAIN_PLANE,
0,
0,0,0
};
pixelFormat = ChoosePixelFormat(hDC, &pfd);
SetPixelFormat (hDC, pixelFormat, &pfd);
}
void StartWGL (HWND hWnd)
{
hDC = GetDC(hWnd);
SetupPixelFormat(hDC);
hRC = wglCreateContext(hDC);
wglMakeCurrent(hDC, hRC);
}
void StopWGL()
{
wglMakeCurrent(hDC, NULL);
wglDeleteContext(hRC);
}
void SetFullScreen()
{
DEVMODE screen = {0};
screen.dmSize = sizeof(DEVMODE);
screen.dmPelsWidth = screen_width;
screen.dmPelsHeight = screen_height;
screen.dmBitsPerPel = screen_bits;
screen.dmDisplayFrequency = screen_frequency;
screen.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY;
ChangeDisplaySettings(&screen, CDS_FULLSCREEN);
}
void sciana(dlugosc, szerokosc, wysokosc)
{
glBegin (GL_QUADS);
glColor3f (0.9f, 0.9f, 0.9f);
glVertex3f (0,0,0);
glVertex3f (dlugosc,0,0);
glVertex3f(dlugosc,szerokosc,0);
glVertex3f (0,szerokosc,0);
glColor3f (0.8f, 0.8f, 0.8f);
glVertex3f (0,szerokosc,0);
glVertex3f (dlugosc,szerokosc,0);
glVertex3f(dlugosc,szerokosc,wysokosc);
glVertex3f (0,szerokosc,wysokosc);
glColor3f (0.7f, 0.7f, 0.7f);
glVertex3f (0,0,0);
glVertex3f (0,szerokosc,0);
glVertex3f(0,szerokosc,wysokosc);
glVertex3f (0,0,wysokosc);
glColor3f (0.6f, 0.6f, 0.6f);
glVertex3f (dlugosc,0,0);
glVertex3f (dlugosc,0,wysokosc);
glVertex3f(dlugosc,szerokosc,wysokosc);
glVertex3f (dlugosc,szerokosc,0);
glColor3f (0.5f, 0.5f, 0.5f);
glVertex3f (0,0,0);
glVertex3f (dlugosc,0,0);
glVertex3f(dlugosc,0,wysokosc);
glVertex3f (0,0,wysokosc);
glColor3f (0.9f, 0.9f, 0.9f);
glVertex3f (0,0,wysokosc);
glVertex3f (dlugosc,0,wysokosc);
glVertex3f(dlugosc,szerokosc,wysokosc);
glVertex3f (0,szerokosc,wysokosc);
glEnd();
}
void SetupRC ()
{
glShadeModel(GL_FLAT);
}
void ChangeSize (int width, int height)
{
glViewport (0,0,width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//gluPerspective(60.0f, (float)width/(float)height, 1.0f, 1000.0f);
glOrtho(-10,10,-10,10,-1,10);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void Render()
{
#define Marcin 1
#define Rafal 2
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor (1.0f, 1.0f, 1.0f, 1.0f);
//gluLookAt (0.0f, 0.0f, 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
//glTranslatef(-1.1,-1.1,0);
//static float kat = 0.0f;
//kat +=0.01f;
//glRotatef (kat, 1.0f, 1.0f, 0.0f);
//glPushMatrix();
//glTranslatef(2,0,0);
//glPushName(1);
//sciana(3,1,2);
//glPopMatrix();
glPushMatrix();
glTranslatef(0,0,0);
glPushName(1);
sciana(4,1,2);
glPopMatrix();
}
#define BUFFER_LENGTH 64
void ProcesSelection(int xPos, int yPos, int width, int height)
{
GLuint selectBuff[BUFFER_LENGTH];
GLint hits, viewport[4];
glSelectBuffer(BUFFER_LENGTH, selectBuff);
glGetIntegerv(GL_VIEWPORT, viewport);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glRenderMode(GL_SELECT);
glLoadIdentity();
gluPickMatrix(xPos, viewport[3] - yPos,2,2,viewport);
//gluPerspective(60.0f, (float)width/(float)height, 1.0f, 1000.0f);
glOrtho(-10,10,-10,10,-1,10);
Render();
hits = glRenderMode(GL_RENDER);
if (hits > 0) {
MessageBox(0, "Trafiony", "", 0);
}
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
}
test(float xPos)
{
char buf [200];
sprintf(buf,"%f",xPos);
MessageBox(0, buf, "", 0);
}