To OpenGL gurus.
- Posted by 1evan at sbcglobal.net May 28, 2003
- 469 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()