1. To OpenGL gurus.
- Posted by 1evan at sbcglobal.net May 28, 2003
- 470 views
I have pared down my program to its bare essentials, moving constant and function definitions to include files. The problem I am having now is that no GL objects are drawn to the screen. I'm guessing it has something to do with getting the rendering context or device context. I really don't know. Any thoughts? include constants.ew --for the windows functions and constants include GLfunc.ew --for the OpenGL functions include GLconst.ew --for the OpenGL constants atom glhRC, glhDC, hWnd, hInstance, ClassName, WindowRect sequence keys keys = repeat(0,256) -- array to hold key presses integer active, retval active = TRUE glhRC = NULL glhDC = NULL hWnd = NULL hInstance = NULL procedure ReSizeGLScene(integer width, integer height) if height = 0 then height = 1 --prevent divide by 0 end if c_proc(glViewport,{0,0,width,height}) c_proc(glMatrixMode,{GL_PROJECTION}) c_proc(glLoadIdentity,{}) c_proc(gluPerspective,{45.0,width/height,0.1,100.0}) c_proc(glMatrixMode,{GL_MODELVIEW}) c_proc(glLoadIdentity,{}) end procedure procedure InitGL() c_proc(glShadeModel,{GL_SMOOTH}) c_proc(glClearColor,{0.0,0.0,0.0,0.0}) c_proc(glClearDepth,{1.0}) c_proc(glEnable,{GL_DEPTH_TEST}) c_proc(glDepthFunc,{GL_LEQUAL}) c_proc(glHint,{GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST}) end procedure procedure DrawGLScene() c_proc(glClear, {or_bits(GL_COLOR_BUFFER_BIT,GL_DEPTH_BUFFER_BIT)}) c_proc(glLoadIdentity, {}) c_proc(glTranslatef, {-1.5,0.0,-6.0}) c_proc(glBegin, {GL_TRIANGLES}) c_proc(glColor3f, {1.0,0.0,0.0}) c_proc(glVertex3f, {0.0,1.0,0.0}) c_proc(glColor3f, {0.0,1.0,0.0}) c_proc(glVertex3f, {-1.0,-1.0,0.0}) c_proc(glColor3f, {0.0,0.0,1.0}) c_proc(glVertex3f, {1.0,-1.0,0.0}) c_proc(glEnd, {}) end procedure function WndProc(atom hWnd, integer uMsg, atom wParam, atom lParam) if uMsg = WM_ACTIVATE then if not floor(wParam/#10000) then active = TRUE else active = FALSE end if elsif uMsg = WM_SYSCOMMAND then if wParam = SC_SCREENSAVE then end if if wParam = SC_MONITORPOWER then end if elsif uMsg = WM_CLOSE then c_proc(PostQuitMessage,{0}) elsif uMsg = WM_KEYDOWN then keys[wParam] = TRUE elsif uMsg = WM_KEYUP then keys[wParam] = FALSE elsif uMsg = WM_SIZE then ReSizeGLScene(and_bits(lParam,#FFFF),floor(lParam/#10000)) end if return c_func(DefWindowProcA,{hWnd, uMsg, wParam, lParam}) end function procedure ClassRegistration() atom WndProcAddress, id, wc id = routine_id("WndProc") if id = -1 then puts(1, "routine_id failed!\n") abort(1) end if WndProcAddress = call_back(id) hInstance = c_func(GetModuleHandleA,{NULL}) ClassName = allocate_string("OpenGL") wc = allocate(40) poke4(wc,or_all({CS_HREDRAW, CS_VREDRAW, CS_OWNDC})) poke4(wc+4,WndProcAddress) poke4(wc+8,0) poke4(wc+12,0) poke4(wc+16,hInstance) poke4(wc+20,c_func(LoadIconA,{NULL,IDI_WINLOGO})) poke4(wc+24,c_func(LoadCursorA,{NULL, IDC_ARROW})) poke4(wc+28,NULL) poke4(wc+32,NULL) poke4(wc+36,ClassName) retval = c_func(RegisterClassA,{wc}) end procedure procedure CreateGLWindow(atom title, integer width, integer height, integer bits) atom PixelFormat, pfd, dwExStyle, dwStyle ClassRegistration() dwExStyle = or_bits(WS_EX_APPWINDOW,WS_EX_WINDOWEDGE) dwStyle = WS_OVERLAPPEDWINDOW WindowRect = allocate(16) poke4(WindowRect,0) poke4(WindowRect + 4,width) poke4(WindowRect + 8, 0) poke4(WindowRect + 12, height) if c_func(AdjustWindowRectEx,{WindowRect, dwStyle, FALSE, dwExStyle}) then end if hWnd = c_func(CreateWindowExA,{dwExStyle, --extended window style ClassName, --class title, --window caption or_all({WS_CLIPSIBLINGS,WS_CLIPCHILDREN,dwStyle}), --window style 0, 0, peek4u(WindowRect + 4) - peek4u(WindowRect), peek4u(WindowRect + 12) - peek4u(WindowRect + 8), NULL, NULL, hInstance, NULL}) pfd = allocate(40) --PIXELFORMATDESCRIPTOR mem_set(pfd,0,40) --clear pfd structure poke(pfd, 40) --size of pfd structure poke(pfd + 2, 1) --version poke4(pfd + 4, or_all({PFD_DRAW_TO_WINDOW,PFD_SUPPORT_OPENGL,PFD_DOUBLEBUFFER})) --properties flags poke(pfd + 8, PFD_TYPE_RGBA) --request an rgba format poke(pfd + 9, bits) --select color depth poke(pfd + 23, 16) --16bit Z-buffer glhDC = c_func(GetDC,{hWnd}) --create GL device context to match window device context PixelFormat = c_func(ChoosePixelFormat,{glhDC,pfd}) --find a pixel format matching PIXELFORMATDESCRIPTOR retval = c_func(SetPixelFormat,{glhDC,PixelFormat,pfd}) retval = c_func(DescribePixelFormat, {glhDC,PixelFormat,40,pfd}) glhRC = c_func(wglCreateContext,{glhDC}) --create GL rendering context retval = c_func(wglMakeCurrent,{glhDC,glhRC}) --make GL device and rendering contexts active retval = c_func(ShowWindow,{hWnd,SW_SHOW}) --show the window retval = c_func(SetForegroundWindow,{hWnd}) --set it to always be in foreground retval = c_func(SetFocus,{hWnd}) --give it focus ReSizeGLScene(width, height) --draw the GL scene to match the window size InitGL() --initialize OpenGL end procedure integer MSG MSG = allocate(28) integer title title = allocate_string("OpenGL") procedure WinMain() integer done, msg_message done = FALSE CreateGLWindow(title,640,480,16) while not done do if c_func(PeekMessageA,{MSG,NULL,0,0,PM_REMOVE}) then msg_message = peek4u(MSG+4) if msg_message = WM_QUIT then done = TRUE else retval = c_func(TranslateMessage,{MSG}) retval = c_func(DispatchMessageA,{MSG}) end if else if active then if keys[VK_ESCAPE] then done = TRUE else DrawGLScene() retval = c_func(SwapBuffers,{glhDC}) end if end if end if end while end procedure WinMain()
2. Re: To OpenGL gurus.
- Posted by stabmaster_ at hotmail.com May 28, 2003
- 449 views
I'm not sure what could be wrong. It works for me if i take your init/display/reshape code and plug it into EuGL. You could try setting pfd.dwLayerMask = PFD_MAIN_PLANE
3. Re: To OpenGL gurus.
- Posted by xerox_irs at lvcm.com May 29, 2003
- 453 views
Hears mine, the window is made by win32lib atom window_dc,g_hRC object junk global procedure init_opengl_window(atom id) atom pfd,pixelformat window_dc=getDC(id) pfd=allocate(38) mem_set(pfd,0,38) poke4(pfd,38)--size poke4(pfd+2,1)--version poke4(pfd+4,or_all({PFD_DRAW_TO_WINDOW, PFD_DOUBLEBUFFER , PFD_SUPPORT_OPENGL}))--flags poke(pfd+9,32)--color_bits poke(pfd+23,32)--depth_bits pixelformat=ChoosePixelFormat(window_dc,pfd) junk= SetPixelFormat(window_dc, pixelformat, pfd) g_hRC=wglCreateContext(window_dc) junk= wglMakeCurrent(window_dc, g_hRC) end procedure > c_proc(glClearDepth,{1.0}) > c_proc(gluPerspective,{45.0,width/height,0.1,100.0}) Increase Your ClearDepth to the last param of gluPerspective and > c_proc(glTranslatef, {-1.5,0.0,-6.0}) May put the puts the c_proc(glVertex3f, {0.0,1.0,0.0}) > c_proc(glColor3f, {0.0,1.0,0.0}) > c_proc(glVertex3f, {-1.0,-1.0,0.0}) > c_proc(glColor3f, {0.0,0.0,1.0}) > c_proc(glVertex3f, {1.0,-1.0,0.0}) Completly Less than z(0.1) or greater that z(1.0)--which should be 100.0 That will do, I think Daniel Kluss ----- Original Message ----- From: <1evan at sbcglobal.net> To: "EUforum" <EUforum at topica.com> Sent: Wednesday, May 28, 2003 12:41 PM Subject: To OpenGL gurus. > > > I have pared down my program to its bare essentials, moving constant and > function definitions to include files. > The problem I am having now is that no GL objects are drawn to the > screen. I'm guessing it has something to do with getting the rendering > context or device context. I really don't know. > Any thoughts? > > include constants.ew --for the windows functions and constants > include GLfunc.ew --for the OpenGL functions > include GLconst.ew --for the OpenGL constants > > atom glhRC, glhDC, hWnd, hInstance, ClassName, WindowRect > sequence keys keys = repeat(0,256) -- array to hold key presses > > integer active, retval > active = TRUE > glhRC = NULL > glhDC = NULL > hWnd = NULL > hInstance = NULL > > procedure ReSizeGLScene(integer width, integer height) > if height = 0 then > height = 1 --prevent divide by 0 > end if > c_proc(glViewport,{0,0,width,height}) > c_proc(glMatrixMode,{GL_PROJECTION}) > c_proc(glLoadIdentity,{}) > c_proc(gluPerspective,{45.0,width/height,0.1,100.0}) > c_proc(glMatrixMode,{GL_MODELVIEW}) > c_proc(glLoadIdentity,{}) > end procedure > > procedure InitGL() > c_proc(glShadeModel,{GL_SMOOTH}) > c_proc(glClearColor,{0.0,0.0,0.0,0.0}) > c_proc(glClearDepth,{1.0}) > c_proc(glEnable,{GL_DEPTH_TEST}) > c_proc(glDepthFunc,{GL_LEQUAL}) > c_proc(glHint,{GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST}) > end procedure > > procedure DrawGLScene() > c_proc(glClear, {or_bits(GL_COLOR_BUFFER_BIT,GL_DEPTH_BUFFER_BIT)}) > c_proc(glLoadIdentity, {}) > c_proc(glTranslatef, {-1.5,0.0,-6.0}) > c_proc(glBegin, {GL_TRIANGLES}) > c_proc(glColor3f, {1.0,0.0,0.0}) > c_proc(glVertex3f, {0.0,1.0,0.0}) > c_proc(glColor3f, {0.0,1.0,0.0}) > c_proc(glVertex3f, {-1.0,-1.0,0.0}) > c_proc(glColor3f, {0.0,0.0,1.0}) > c_proc(glVertex3f, {1.0,-1.0,0.0}) > c_proc(glEnd, {}) > end procedure > > > function WndProc(atom hWnd, integer uMsg, atom wParam, atom lParam) > if uMsg = WM_ACTIVATE then > if not floor(wParam/#10000) then > active = TRUE > else > active = FALSE > end if > elsif uMsg = WM_SYSCOMMAND then > if wParam = SC_SCREENSAVE then end if > if wParam = SC_MONITORPOWER then end if > elsif uMsg = WM_CLOSE then > c_proc(PostQuitMessage,{0}) > elsif uMsg = WM_KEYDOWN then > keys[wParam] = TRUE > elsif uMsg = WM_KEYUP then > keys[wParam] = FALSE > elsif uMsg = WM_SIZE then > ReSizeGLScene(and_bits(lParam,#FFFF),floor(lParam/#10000)) > end if > return c_func(DefWindowProcA,{hWnd, uMsg, wParam, lParam}) > end function > > > procedure ClassRegistration() > atom WndProcAddress, id, wc > id = routine_id("WndProc") > if id = -1 then > puts(1, "routine_id failed!\n") > abort(1) > end if > WndProcAddress = call_back(id) > hInstance = c_func(GetModuleHandleA,{NULL}) > ClassName = allocate_string("OpenGL") > wc = allocate(40) > poke4(wc,or_all({CS_HREDRAW, CS_VREDRAW, CS_OWNDC})) > poke4(wc+4,WndProcAddress) > poke4(wc+8,0) > poke4(wc+12,0) > poke4(wc+16,hInstance) > poke4(wc+20,c_func(LoadIconA,{NULL,IDI_WINLOGO})) > poke4(wc+24,c_func(LoadCursorA,{NULL, IDC_ARROW})) > poke4(wc+28,NULL) <snip> > retval = c_func(wglMakeCurrent,{glhDC,glhRC}) --make GL device and > rendering contexts active > retval = c_func(ShowWindow,{hWnd,SW_SHOW}) --show the window > retval = c_func(SetForegroundWindow,{hWnd}) --set it to always be in > foreground > retval = c_func(SetFocus,{hWnd}) --give it focus > ReSizeGLScene(width, height) --draw the GL scene to match the > window size > InitGL() --initialize OpenGL > end procedure > > integer MSG MSG = allocate(28) > integer title title = allocate_string("OpenGL") > procedure WinMain() > integer done, msg_message > done = FALSE > CreateGLWindow(title,640,480,16) > while not done do > if c_func(PeekMessageA,{MSG,NULL,0,0,PM_REMOVE}) then > msg_message = peek4u(MSG+4) > if msg_message = WM_QUIT then > done = TRUE > else > retval = c_func(TranslateMessage,{MSG}) > retval = c_func(DispatchMessageA,{MSG}) > end if > else > if active then > if keys[VK_ESCAPE] then > done = TRUE > else > DrawGLScene() > retval = c_func(SwapBuffers,{glhDC}) > end if > end if > end if > end while > end procedure > WinMain() > > > > TOPICA - Start your own email discussion group. FREE! > >
4. Re: To OpenGL gurus.
- Posted by 1evan at sbcglobal.net May 29, 2003
- 451 views
A clue perhaps? If I change the parameters in glTranslatef so the first two are a positive value less than one and the third parameter equals 0, I get what looks like a rapidly vertically scrolling triangle. Weirder yet is the fact that as I change the parameters, the color of the triangle changes. My glTranslatef definition is: glTranslatef = link_c_proc(gl, "glTranslatef", {C_FLOAT,C_FLOAT,C_FLOAT}) Why are you using pfd = allocate(38)? The PIXELFORMATDESCRIPTOR size is 40. I tried 38 and it didn't make any difference though. xerox_irs at lvcm.com wrote: > > >Hears mine, the window is made by win32lib > >atom window_dc,g_hRC >object junk >global procedure init_opengl_window(atom id) > atom pfd,pixelformat > window_dc=getDC(id) > pfd=allocate(38) > mem_set(pfd,0,38) > poke4(pfd,38)--size > poke4(pfd+2,1)--version > poke4(pfd+4,or_all({PFD_DRAW_TO_WINDOW, PFD_DOUBLEBUFFER , >PFD_SUPPORT_OPENGL}))--flags > poke(pfd+9,32)--color_bits > poke(pfd+23,32)--depth_bits > pixelformat=ChoosePixelFormat(window_dc,pfd) > junk= SetPixelFormat(window_dc, pixelformat, pfd) > g_hRC=wglCreateContext(window_dc) > junk= wglMakeCurrent(window_dc, g_hRC) >end procedure > > >> c_proc(glClearDepth,{1.0}) >> c_proc(gluPerspective,{45.0,width/height,0.1,100.0}) >> >> >Increase Your ClearDepth to the last param of gluPerspective >and > > >> c_proc(glTranslatef, {-1.5,0.0,-6.0}) >> >> >May put the puts the > c_proc(glVertex3f, {0.0,1.0,0.0}) > > >> c_proc(glColor3f, {0.0,1.0,0.0}) >> c_proc(glVertex3f, {-1.0,-1.0,0.0}) >> c_proc(glColor3f, {0.0,0.0,1.0}) >> c_proc(glVertex3f, {1.0,-1.0,0.0}) >> >> >Completly Less than z(0.1) or greater that z(1.0)--which should be 100.0 > >That will do, I think >Daniel Kluss > >----- Original Message ----- >From: <1evan at sbcglobal.net> >To: "EUforum" <EUforum at topica.com> >Sent: Wednesday, May 28, 2003 12:41 PM >Subject: To OpenGL gurus. > > >>I have pared down my program to its bare essentials, moving constant and >>function definitions to include files. >>The problem I am having now is that no GL objects are drawn to the >>screen. I'm guessing it has something to do with getting the rendering >>context or device context. I really don't know. >>Any thoughts? >> >>include constants.ew --for the windows functions and constants >>include GLfunc.ew --for the OpenGL functions >>include GLconst.ew --for the OpenGL constants >> >>atom glhRC, glhDC, hWnd, hInstance, ClassName, WindowRect >>sequence keys keys = repeat(0,256) -- array to hold key presses >> >>integer active, retval >>active = TRUE >>glhRC = NULL >>glhDC = NULL >>hWnd = NULL >>hInstance = NULL >> >>procedure ReSizeGLScene(integer width, integer height) >> if height = 0 then >> height = 1 --prevent divide by 0 >> end if >> c_proc(glViewport,{0,0,width,height}) >> c_proc(glMatrixMode,{GL_PROJECTION}) >> c_proc(glLoadIdentity,{}) >> c_proc(gluPerspective,{45.0,width/height,0.1,100.0}) >> c_proc(glMatrixMode,{GL_MODELVIEW}) >> c_proc(glLoadIdentity,{}) >>end procedure >> >>procedure InitGL() >> c_proc(glShadeModel,{GL_SMOOTH}) >> c_proc(glClearColor,{0.0,0.0,0.0,0.0}) >> c_proc(glClearDepth,{1.0}) >> c_proc(glEnable,{GL_DEPTH_TEST}) >> c_proc(glDepthFunc,{GL_LEQUAL}) >> c_proc(glHint,{GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST}) <snip> > >
5. Re: To OpenGL gurus.
- Posted by xerox_irs at lvcm.com May 29, 2003
- 479 views
(38) Must have been a different version(?or a mistake) but it works ok, look at my opengl demo in the recent contibutions. The color changes because when it clips in interpolates the color funny Strange, look at my demo, at the one with projection and compare them. Daniel Kluss ----- Original Message ----- From: <1evan at sbcglobal.net> To: "EUforum" <EUforum at topica.com> Subject: Re: To OpenGL gurus. > > > A clue perhaps? > If I change the parameters in glTranslatef so the first two are a > positive value less than one and the third parameter equals 0, I get > what looks like a rapidly vertically scrolling triangle. Weirder yet is > the fact that as I change the parameters, the color of the triangle changes. > My glTranslatef definition is: glTranslatef = link_c_proc(gl, > "glTranslatef", {C_FLOAT,C_FLOAT,C_FLOAT}) > > Why are you using pfd = allocate(38)? The PIXELFORMATDESCRIPTOR size is > 40. I tried 38 and it didn't make any difference though. > > xerox_irs at lvcm.com wrote: > > > > >Hears mine, the window is made by win32lib > > > >atom window_dc,g_hRC > >object junk > >global procedure init_opengl_window(atom id) > > atom pfd,pixelformat > > window_dc=getDC(id) > > pfd=allocate(38) > > mem_set(pfd,0,38) > > poke4(pfd,38)--size > > poke4(pfd+2,1)--version > > poke4(pfd+4,or_all({PFD_DRAW_TO_WINDOW, PFD_DOUBLEBUFFER , > >PFD_SUPPORT_OPENGL}))--flags > > poke(pfd+9,32)--color_bits > > poke(pfd+23,32)--depth_bits > > pixelformat=ChoosePixelFormat(window_dc,pfd) > > junk= SetPixelFormat(window_dc, pixelformat, pfd) > > g_hRC=wglCreateContext(window_dc) > > junk= wglMakeCurrent(window_dc, g_hRC) > >end procedure > > > > > >> c_proc(glClearDepth,{1.0}) > >> c_proc(gluPerspective,{45.0,width/height,0.1,100.0}) > >> > >> > >Increase Your ClearDepth to the last param of gluPerspective > >and > > > > > >> c_proc(glTranslatef, {-1.5,0.0,-6.0}) > >> > >> > >May put the puts the > > c_proc(glVertex3f, {0.0,1.0,0.0}) > > > > > >> c_proc(glColor3f, {0.0,1.0,0.0}) > >> c_proc(glVertex3f, {-1.0,-1.0,0.0}) > >> c_proc(glColor3f, {0.0,0.0,1.0}) > >> c_proc(glVertex3f, {1.0,-1.0,0.0}) > >> > >> > >Completly Less than z(0.1) or greater that z(1.0)--which should be 100.0 > > > >That will do, I think > >Daniel Kluss > > > >----- Original Message ----- > >From: <1evan at sbcglobal.net> > >To: "EUforum" <EUforum at topica.com> > >Sent: Wednesday, May 28, 2003 12:41 PM > >Subject: To OpenGL gurus. > > > > > >>I have pared down my program to its bare essentials, moving constant and > >>function definitions to include files. > >>The problem I am having now is that no GL objects are drawn to the > >>screen. I'm guessing it has something to do with getting the rendering > >>context or device context. I really don't know. > >>Any thoughts? > >> > >>include constants.ew --for the windows functions and constants > >>include GLfunc.ew --for the OpenGL functions > >>include GLconst.ew --for the OpenGL constants > >> > >>atom glhRC, glhDC, hWnd, hInstance, ClassName, WindowRect > >>sequence keys keys = repeat(0,256) -- array to hold key presses > >> > >>integer active, retval > >>active = TRUE > >>glhRC = NULL > >>glhDC = NULL > >>hWnd = NULL > >>hInstance = NULL > >> > >>procedure ReSizeGLScene(integer width, integer height) > >> if height = 0 then > >> height = 1 --prevent divide by 0 > >> end if > >> c_proc(glViewport,{0,0,width,height}) > >> c_proc(glMatrixMode,{GL_PROJECTION}) > >> c_proc(glLoadIdentity,{}) > >> c_proc(gluPerspective,{45.0,width/height,0.1,100.0}) > >> c_proc(glMatrixMode,{GL_MODELVIEW}) > >> c_proc(glLoadIdentity,{}) > >>end procedure > >> > >>procedure InitGL() > >> c_proc(glShadeModel,{GL_SMOOTH}) <snip> > >
6. Re: To OpenGL gurus.
- Posted by stabmaster_ at hotmail.com May 29, 2003
- 453 views
>A clue perhaps? >If I change the parameters in glTranslatef so the first two are a positive >value less than one and the third parameter equals 0, I get what looks like >a rapidly vertically scrolling triangle. Weirder yet is the fact that as I >change the parameters, the color of the triangle changes. >My glTranslatef definition is: glTranslatef = link_c_proc(gl, >"glTranslatef", {C_FLOAT,C_FLOAT,C_FLOAT}) Scrolling? Sounds like you're forgetting to reset the modelview matrix. Did you remove the LoadIdentity call? Anyway, the display-code you posted in your first mail was fine, it drew a red-green-blue triangle at the left side of the window.