Cześć,
Chciałbym was prosić o pomoc przy budowie walca, wiem, że są gotowe biblioteki dzięki,którym już mógłbym użyć funkcji,która sama mi go narysuje ale jednak postanowiłem zrobić to sam.
To jest mój kod:
#include <windows.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <math.h>
#pragma comment(lib,"opengl32.lib")
#pragma comment(lib,"glu32.lib")
#define PI 3.1415
GLfloat x=90.0;
GLfloat y=90.0;
GLfloat z=0.0;
GLfloat angle=0;
GLfloat i;
void InitGL(void)
{
glClearColor(0.0f,0.0f,0.0f,0.0f);
}
void tri()
{
glScalef(1,1,1);
//glBegin(GL_TRIANGLES);
glBegin(GL_TRIANGLE_STRIP);
glColor3f(1,0,0);
glVertex3f(-1,0,0);
glVertex3f(0,1,0);
glVertex3f(1,0,0);
glVertex3f(1,1,0);
glEnd();
}
void DrawGLScene(void)
{
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(50,4.0f/3.0f,1,100);
glTranslatef(0,0,-10);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushMatrix();
glRotatef(GetTickCount()/10,1,0,0);
for(i=0;i<360;i++){
glRotatef(10,0,1,0);
glTranslatef(1,0,0);
glPushMatrix();
glRotatef(5,0,1,0);
tri();
glPopMatrix();
}
glPopMatrix();
}
HGLRC hRC = NULL;
HDC hDC = NULL;
HWND hWnd = NULL;
HINSTANCE hInstance = NULL;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
bool CreateGLWindow(char* title, int width, int height)
{
GLuint PixelFormat;
WNDCLASS wc;
RECT WindowRect;
WindowRect.left = (long)0;
WindowRect.right = (long)width;
WindowRect.top = (long)0;
WindowRect.bottom = (long)height;
LPCWSTR nazwa = TEXT("Start");
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 = nazwa;
RegisterClass(&wc);
hWnd = CreateWindowEx( WS_EX_APPWINDOW | WS_EX_WINDOWEDGE, nazwa,
nazwa,
WS_SYSMENU |
WS_CLIPSIBLINGS |
WS_CLIPCHILDREN,
0, 0,
width,
height,
NULL,
NULL,
hInstance,
NULL);
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
};
hDC=GetDC(hWnd);
PixelFormat=ChoosePixelFormat(hDC,&pfd);
HRESULT rez = SetPixelFormat(hDC,PixelFormat,&pfd);
hRC=wglCreateContext(hDC);
wglMakeCurrent(hDC,hRC);
ShowWindow(hWnd,SW_SHOW);
InitGL();
return true;
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch (uMsg)
{
case WM_ACTIVATE:
{
return 0;
}
case WM_CLOSE:
{
PostQuitMessage(0);
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 (!CreateGLWindow(NULL,800,600))
{
return 0;
}
while(!done)
{
if (PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
{
if (!GetMessage(&msg, 0, 0, 0)) done=true;
else {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else
{
DrawGLScene();
SwapBuffers(hDC);
}
}
return (msg.wParam);
}
No i teraz niby coś tam rysuje ale to nie to na pewno co powinno być bo kod nie jest uniwersalny i nie można go skalować. Dlatego proszę o pomoc bo siedzę nad tym 3 godziny i już się zaczynam denerwować.
Pozdrawiam!