Skip to main content
GameDev.net gamedev.net
🔒 Locked

Help i have a problem

Started by Cyberman Dec 22, 2001 at 2:36 PM 15 replies 350+ views
Original Post
Cyberman
Cyberman
what''s wrong in my code? ---------------------------------------------------------------- #include "stdafx.h" #include "resource.h" #include #include #include void OpenGl(HWND hwnd,HDC *hdc,HGLRC *hrc); void DrawGL(HDC dc,float x,float y); LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wp,LPARAM lp); GLfloat y=0.0f; GLfloat x=0.0f; int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { HWND hwnd; MSG msg; WNDCLASS wnd; HDC dc; HGLRC hgl; wnd.cbClsExtra=0; wnd.cbWndExtra=0; wnd.hbrBackground=(HBRUSH)(COLOR_WINDOW+3); wnd.hCursor=NULL; wnd.hIcon=NULL; wnd.hInstance=hInstance; wnd.lpfnWndProc=WndProc; wnd.lpszClassName="Window"; wnd.lpszMenuName=(char *)IDR_MENU1; wnd.nostyle=CS_VREDRAW|CS_HREDRAW; if(!RegisterClass(&wnd))return false; hwnd=CreateWindow("Window","Window",WS_SYSMENU,100,100,400,400,NULL,NULL,hInstance,NULL); ShowWindow(hwnd,nCmdShow); OpenGl(hwnd,&dc,&hgl); SetTimer(hwnd,1,1,NULL); while(GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return 0; } LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wp,LPARAM lp) { switch(msg) { case WM_CLOSE: PostQuitMessage(1); break; case WM_TIMER: DrawGL(GetDC(hwnd),x,y); break; case WM_COMMAND: switch(wp) { case ID_FILE_QUIT: PostQuitMessage(1); break; } break; } return DefWindowProc(hwnd,msg,wp,lp); } void OpenGl(HWND hwnd,HDC *hdc,HGLRC *hrc) { *hdc=GetDC(hwnd); PIXELFORMATDESCRIPTOR pfd; pfd.cColorBits=24; pfd.cDepthBits=32; pfd.dwFlags = PFD_DOUBLEBUFFER; SetPixelFormat(*hdc,ChoosePixelFormat(*hdc,&pfd),&pfd); *hrc=wglCreateContext(*hdc); glShadeModel(GL_SMOOTH); wglMakeCurrent(*hdc,*hrc); } void DrawGL(HDC dc,float x,float y) { glClear(GL_COLOR_BUFFER_BIT); glViewport(-100,-100,GLsizei(400),GLsizei(400)); glBegin(GL_TRIANGLES); glVertex3f(0.2f,0.0f,0.0f); glVertex3f(0.0f,0.2f,0.0f); glVertex3f(0.0f,0.0f,0.0f); glEnd(); glTranslatef(0.4f,0.0f,0.0f); glRotatef(10.0f,x,y,0.0); glBegin(GL_TRIANGLES); glVertex3f(0.4f,0.0f,0.0f); glVertex3f(0.0f,0.2f,0.0f); glVertex3f(0.0f,0.0f,0.4f); glEnd(); SwapBuffers(dc); } --------------------------------------
python_regious
python_regious
Well, many things.

Firstly, WS_CLIPSIBLINGS and WS_CLIPCHILDREN are required for OpenGL.

Also, you want PFD_DRAW_TO_WINDOW and PFD_SUPPORT_OPENGL as flags in your pixelformatdescriptor structure.


Death of one is a tragedy, death of a million is just a statistic.
If at first you don't succeed, redefine success.
Cyberman
Cyberman
what''s those and for what i need them and do i need matrix?
LessBread
LessBread
You'll want to change the parameters to CreateWindow like so

      
hwnd=CreateWindow("Window","Window",
WS_SYSMENU | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
100,100,400,400,NULL,NULL,hInstance,NULL);


And inside your OpenGl function you'll want to change this line like so

        
pfd.dwFlags = PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;


this looks sketchy too:

  
wnd.nostyle=CS_VREDRAW|CS_HREDRAW;


It should be

  
wnd.style=CS_VREDRAW|CS_HREDRAW;


but the inserted "no" might have something to do with the way this forum operates...

‘But truth's a menace, science a public danger.’ Brave New World, Aldous Huxley

Edited by - lessbread on December 22, 2001 4:59:29 PM

Edited by - lessbread on December 22, 2001 5:01:35 PM
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Cyberman
Cyberman
my problem is that the object''s move and get out from the screen

i put the translate just for separate the objects from each other and instead it''s move the object''s from the screen

python_regious
python_regious
Put "glLoadIdentity()" at the beginning of your DrawGL function.

Death of one is a tragedy, death of a million is just a statistic.
If at first you don't succeed, redefine success.
Cyberman
Cyberman
why?
Cyberman
Cyberman
ok it''s work now i want to rotate the objects and it''s not work
Cyberman
Cyberman
ok it''s work now i want to rotate the objects and it''s not work

i put a loop that inc the x and y but it''s not work
python_regious
python_regious
My advice, buy a book on OpenGL. The OpenGL Superbible is a rather good one. Also, get yourself over to Nehe, there are a great many tutorials on OpenGL there.

Death of one is a tragedy, death of a million is just a statistic.
If at first you don't succeed, redefine success.
Cyberman
Cyberman
i dont want to start to buy books i want to get it on
on myself so no one can i answer to my little question
python_regious
python_regious
The point is this, we could give you code that rotates your little triangle, but then you won''t learn anything. You need to learn how to do it, not just cut and paste other peoples code in and then say "bingo-I did it", because you wouldn''t have. You can''t rush these things, take your time and try and learn the methods used. It also seems like you need learn a bit more maths, ie, transformations...

Death of one is a tragedy, death of a million is just a statistic.
If at first you don't succeed, redefine success.
Cyberman
Cyberman
are you kidding me i dont copy and paste anybody codes i learn the tutorials from nehe and i''m stuck so i ask for help and all of you make such a big deal from it
python_regious
python_regious
OK, what EXACTLY do you want to do? Rotate your triangle? On the spot? We need more information on what you want to do than that.

Post your newest code, and put it between [ source ] and [ /source ] ( without the spaces ).

Death of one is a tragedy, death of a million is just a statistic.
If at first you don't succeed, redefine success.
Cyberman
Cyberman
ok it''s work
Zeus_
Zeus_
I think it''s funny when people post things like this..

"Whats wrong with my code?" and post an entire project of code... Why do they do it? Are they just too lazy to do find it themselves?

I think that he just copy+pasted some code and cant figure out why it didn''t work... But that''s just me..


And for future reference, we posters here try NOT to just give you the direct answer. WHat happens there? You get what you want, but what do you learn? A nast habbit. YOu learn that you can come here and post some silly question and get code for what you want to do. That is bad. THat is not coding...

Therefore! Research your topic first, then you can post stuff like

"I read an article about the functions you need to use to rotate a triangle, but I am still confused about how they work. Could someone explain it to me? Thanks."

Isn''t that much better than

"What''s wrong in my code?

#inclue ... [blahblahblah]
"

I think so. =)

Have a happy Christmas.
Cyberman
Cyberman
lol

i didn''t copy and paste my code i asked what''s wrong my code

because i didn''t know how to explain my problem

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.