• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.


  • Content count

  • Joined

  • Last visited

Community Reputation

130 Neutral

About LeLorrain

  • Rank
  1. Hello people, I am new to windows graphic on my way to learn directx by myself, and, of course, I hit a brick wall! To start in the tutorial I use, the display of my rendering is done with GDI and all I get is a black window. I wonder if any of you would be nice enough to take a look at my code and tell me what I did wrong. Please, no comment on the use of GDI, I'll get to display with DirectX in the next lesson. The first lesson was to teach me about rendering 3D on a 2D screen and the various transformations to do it, although we use DirectX to handle the matrices. From what I see, the vertex coordinates at the "DrawLine" method are correct and fit in the window Rect. The objects are two rotating cubes in wireframe. Here is the relevant code: [CODE] bool GameApp::BuildBuffer ( long width, long height ) { HDC hDC = ::GetDC (m_hWnd); if (NULL == m_hDC) { m_hDC = ::CreateCompatibleDC (hDC); } m_hBackBuffer = ::CreateCompatibleBitmap (hDC, width, height); if (NULL == m_hBackBuffer) { return false; } m_hSavedBuffer = (HBITMAP)::SelectObject (hDC, m_hBackBuffer); ::ReleaseDC (m_hWnd, hDC); ::SetBkMode (m_hDC, TRANSPARENT); return true; } void GameApp::SetupGameState ( void ) { /********************************\ * View matrix with: * * Right = ( 1, 0, 0 ) * Up = ( 0, 1, 0 ) * Eye = ( 0, 0, 1 ) * origin = ( 0, 0, 0 ) * (window origin) * \********************************/ // Set the View matrice to Identity D3DXMatrixIdentity (&m_View); /********************************\ * * Perspective Matrix with: * * FOV: 60° * Aspect: Width / Height * Near: 1.01 * Far: 1000.00 * \********************************/ // Set the Perspective Matrix D3DXMatrixPerspectiveFovLH (&m_Projection, (float)D3DXToRadian (60.0), (float)m_ViewWidth / (float)m_ViewHeight, 1.01, 1000.0); return; } int GameApp::BeginGame ( void ) { MSG msg; int rc = 0; // Start main loop while (true) { if (::PeekMessage (&msg, NULL, 0, 0,PM_REMOVE)) { if (WM_QUIT == msg.message) { rc = msg.wParam; break; } ::TranslateMessage (&msg); ::DispatchMessage (&msg); } else { FrameAdvance (); } } return rc; } void GameApp::FrameAdvance ( void ) { // Limit to 60 frames per seconds m_Timer.LockFPS (60); // Animate the objects AnimateObjects ((float)m_Timer.GetIntervalSeconds()); // Clear the buffer ClearBuffer (0x00FFFFFF); // Draw objects for (size_t i = 0; i < m_Objects.size(); ++i) { Mesh * mesh = &m_Objects[i]->m_Mesh; // Loop on each polygon for (size_t j = 0; j < mesh->m_Polygon.size(); ++j) { DrawPolygon (&mesh->m_Polygon[j], &m_Objects[i]->m_World); } } // Add the frames per second stringstream ss; ss << "f/s " << (int)m_Timer.GetFPS() << ends; TextOut (m_hDC, 5, 5, ss.str().c_str(), ss.str().size()); // Display all DisplayScene (); // Success! return; } void GameApp::AnimateObjects ( float deltaTime ) { for (size_t i = 0; i < m_Objects.size(); ++i) { if (m_Objects[i]->m_Rotation) { D3DXMATRIX rotate; D3DXMatrixRotationYawPitchRoll (&rotate, (float)(D3DXToRadian (75.0) * deltaTime), (float)(D3DXToRadian (75.0) * deltaTime), (float)(D3DXToRadian (75.0) * deltaTime)); m_Objects[i]->m_World = rotate * m_Objects[i]->m_World; } } return; } void GameApp::ClearBuffer ( D3DCOLOR colour ) { // Setup the brush to paint the buffer LOGBRUSH logBrush; logBrush.lbColor = (COLORREF)(0x00FFFFFF & colour); logBrush.lbStyle = BS_SOLID; logBrush.lbHatch = NULL; // Create the brush HBRUSH hBrush = ::CreateBrushIndirect (&logBrush); // Put it into the frame buffer HBRUSH hOldBrush = (HBRUSH)::SelectObject (m_hDC, hBrush); LOGPEN pen; // Setup the pen invisible pen.lopnStyle = PS_NULL; pen.lopnWidth.x = 1; pen.lopnWidth.y = 1; pen.lopnColor = 0; // Create the pen HPEN hPen = ::CreatePenIndirect (&pen); // Put it into the frame buffer HPEN hOldPen = (HPEN)::SelectObject (m_hDC, hPen); // Draw a rectangle covering the Window ::Rectangle (m_hDC, m_ViewX, m_ViewY, (m_ViewX + m_ViewWidth), (m_ViewY + m_ViewHeight)); // Restore the old brush ::SelectObject (m_hDC, hOldBrush); // Destroy Rendering brush ::DeleteObject (hBrush); // Restore the old pen ::SelectObject (m_hDC, hOldPen); // Destroy Rendering pen ::DeleteObject (hPen); return; } void GameApp::DrawPolygon ( Polygon * polygon, const D3DXMATRIX * world) { D3DXVECTOR3 vertex0, vertex1; size_t n = polygon->m_Vertex.size(); // Loop thru each vector for (size_t i = 0; i < n + 1; ++i) { // Transform first vertex to world space vertex1 = (polygon->m_Vertex[i % n]).SetD3Dvector(); D3DXVec3TransformCoord (&vertex1, &vertex1, world); // Transform to view space D3DXVec3TransformCoord (&vertex1, &vertex1, &m_View); // Convert to screen space D3DXVec3TransformCoord (&vertex1, &vertex1, &m_Projection); // Convert to window coords vertex1.x = m_ViewX + m_ViewWidth * (vertex1.x + 1.0) / 2; vertex1.y = m_ViewY + m_ViewHeight * (1.0 - vertex1.y) / 2; // If this is not the first, draw if (i > 0) { DrawLine (vertex0, vertex1, 0x00FFFFFF); } vertex0 = vertex1; } // Success! return; } void GameApp::DrawLine ( const D3DXVECTOR3 &v0, const D3DXVECTOR3 &v1, const D3DCOLOR colour ) { LOGPEN pen; // Setup the rendering pen pen.lopnStyle = PS_SOLID; pen.lopnWidth.x = 2; pen.lopnWidth.y = 1; pen.lopnColor = (COLORREF)(0x00FFFFFF & colour); // Create the rendering pen HPEN hPen = ::CreatePenIndirect (&pen); // Put it into the frame buffer HPEN hOldPen = (HPEN)::SelectObject (m_hDC, hPen); // Draw the line segment ::MoveToEx (m_hDC, (long)v0.x, (long)v0.y, NULL); LineTo (m_hDC, (long)v1.x, (long)v1.y); // Restore the old pen ::SelectObject (m_hDC, hOldPen); // Destroy Rendering pen ::DeleteObject (hPen); // Success! return; } void GameApp::DisplayScene ( void ) { HDC hDC = ::GetDC (m_hWnd); // Move the back buffer to the screen ::BitBlt (hDC, m_ViewX, m_ViewY, m_ViewWidth, m_ViewHeight, m_hDC, m_ViewX, m_ViewY, SRCCOPY); // Cleanup ::ReleaseDC (m_hWnd, hDC); return; } [/CODE]
  2. [quote name='Burnt_Fyr' timestamp='1305233384' post='4809949']<br />[quote name='LeLorrain' timestamp='1305224939' post='4809887']<br />I just finished going through the code of Chapter 6 but there is an aspect that bugs me. I do not understand how the various methods in ZFXD3Dmisc.cpp are used... in particular, in InitStage, the 3D perspective and orthogonal matrices are computed, but there is no definition of the near and far planes that are used in the computation! Nowhere in the chapter are there any indications on when the View and Projection matrices are created; SetView3D just update existing matrices, SetClipping Planes too!<br /><br />Should'nt the sequence of call be:<br /><br /> InitStage &nbsp;&nbsp;&nbsp; (Initialize the with default values)<br /> SetMode &nbsp;&nbsp;&nbsp; (Setup the D3D viewport)<br /><br />then a call to create the view and projection matrices followed by:<br /><br /> SetView3D &nbsp;&nbsp;&nbsp; (Modify the matrices)<br /> SetClipping (Modify the matrices)<br /><br />What am I missing? The rest of the chapter is about Shader and Vertex rendering.<br /><br />Thanks,<br /><br />LeLorrain<br />[/quote]<br /><br />Well You could always step through the code... I gave up on that book myself, only because I was working with a newer sdk, which meant half of the code was broken, and I wasn't adept enough to figure out why at that point in time. IMO his later book is much better, but that could just be because I understand so much more of what is going on than before.<br />[/quote]<br /><br /><br /> I have the 2004 edition which uses the SDK of D3D9c (Which is the SDK I have) I do intend to continue looking at the code, it is just that I do not like to do something without understanding why I am doing it and to what purpose... and the way these methods are presented do not make sense to me. Also the demo sample given on the CD is not very enlightening for that matter.
  3. [quote name='NEXUSKill' timestamp='1305228417' post='4809908']<br />you are missing mentioning the chapter 6 of what book you got stuck on <img src='http://public.gamedev.net/public/style_emoticons/default/wink.gif' class='bbc_emoticon' alt='' /><br /><br /><br />[/quote]<br /><br /><br /> Sorry, I thought that the heading of the message was enough... the book is "3D Game Engine Programming" by Stefan Zerbst & Oliver Düvel.
  4. I just finished going through the code of Chapter 6 but there is an aspect that bugs me. I do not understand how the various methods in ZFXD3Dmisc.cpp are used... in particular, in InitStage, the 3D perspective and orthogonal matrices are computed, but there is no definition of the near and far planes that are used in the computation! Nowhere in the chapter are there any indications on when the View and Projection matrices are created; SetView3D just update existing matrices, SetClipping Planes too! Should'nt the sequence of call be: InitStage (Initialize the with default values) SetMode (Setup the D3D viewport) then a call to create the view and projection matrices followed by: SetView3D (Modify the matrices) SetClipping (Modify the matrices) What am I missing? The rest of the chapter is about Shader and Vertex rendering. Thanks, LeLorrain
  5. Programmer16: Adaptor Identifier provides the same name for both (e.g. "ATI Radeon HD 4800 Series") but the device names are different (\\.\DISPLAY1 and \\.\DISPLAY2.) My problem is that I also get both monitor devices on each adaptor. I do Have in the enumeration the registry keys, so i guess I'm gonna have to dig into it if I really want to find the monitor names. Now, I realize that it would be useless if both monitors were identical! So I might as well forget about it!
  6. Hummm... "GetPhysicalMonitorsFromIDirect3DDevice9" could do it, Mat, but MSDN says that it works only with Vista and up and I am using XP. Nevertheless, I will try it and report the results. <<edited: "undeclared identifier"!>> There is also "GetPhysicalMonitorsFromHMONITOR" which also works only on Vista+! Thanks. [Edited by - LeLorrain on April 29, 2010 11:14:59 PM]
  7. Hi! I have found that I can get the monitor name using "EnumDisplayDevices()" but, how do I re-conciliate the results with D3D enumeration? I have one graphics adapter with two monitors and I get the following results: EnumDisplayDevices: Two displays, each with two monitors \\.\DISPLAY1\MONITOR0 and \\.\DISPLAY1\MONITOR1 \\.\DISPLAY2\MONITOR0 and \\.\DISPLAY1\MONITOR1 (Note: I did retain only the display with flag "DISPLAY_DEVICE_ATTACHED_TO_DESKTOP") D3DEnumeration: Two adapters \\.\DISPLAY1 \\.\DISPLAY2 Do I have to assume the display1 will ALWAYS have monitor0 attached and display2 monitor1? (From the maximum resolution given by the enumeration that seem to be case: monitor0 has 1920x1200 and monitor1 has 2048 x 1536.) Or is there a way to differentiate? Thanks. LeLorrain
  8. Thanks Endurion for your reply. Yes, you are right, I should have checked the result with FAILED(), which seems to be the way to do in DirectX! Further analysis of the HRESULT gave me a "D3DERR_INVALIDCALL" error code ant it seems that the device did not like the multi-sample value of 16 that the enumeration gave me for the combo of the adaptor... Hard-coding the value, I found that it would accept up to 8 samples. Again, thank you. LeLorrain
  9. I am trying to learn how to use DirectX9 under Win/XP and I and I have aproblem with multiple windowed view rendering. My windows are created as well as the D3D device. but when I get to the "CreateAdditionalSwapChain" statement, I get an access violation! Any help would be much appreciated... Thanks. LeLorrain Here is the relevant code: HRESULT D3Dgraphics::StartGraphics ( void ) { DEVICEINFO * device = m_D3Denum->getDevice(); COMBOINFO * combo = NULL; if (m_D3Dsystem != NULL) { m_D3Dsystem->Release (); m_D3Dsystem = NULL; } m_D3Dsystem = Direct3DCreate (D3D_SDK_VERSION); if (NULL == m_D3Dsystem) { throw Exception ("D3Dgraphics::StartGraphics", __LINE__, ::GetLastError(), "Graphic system not created"); } // Look for the graphic device for (UINT i = 0; i < device->D3DCombo.size(); i++) { bool Windowed = device->D3DCombo[i].Windowed; if ((device->D3DCombo[i].Windowed == m_Windowed) && (device->D3DCombo[i].D3DDevType == device->D3DDevType) && (device->D3DCombo[i].fmtAdapter == D3DdeviceInfo.AdapterFormat) && (device->D3DCombo[i].fmtBackBuffer == D3DdeviceInfo.BackBufferFmt) ) { combo = &device->D3DCombo[i]; break; } } memset ((void *)&D3DdeviceInfo.D3Dparams, 0, sizeof (D3DdeviceInfo.D3Dparams)); D3DdeviceInfo.D3Dparams.Windowed = m_Windowed; D3DdeviceInfo.D3Dparams.BackBufferCount = 1; D3DdeviceInfo.D3Dparams.BackBufferFormat = D3DdeviceInfo.DisplayMode.Format; D3DdeviceInfo.D3Dparams.EnableAutoDepthStencil = true; D3DdeviceInfo.D3Dparams.AutoDepthStencilFormat = combo->fmtDepthStencil; D3DdeviceInfo.D3Dparams.MultiSampleType = combo->msType; D3DdeviceInfo.D3Dparams.SwapEffect = D3DSWAPEFFECT_DISCARD; // Check the stencil buffer depth if ((D3DFMT_D24S8 == combo->fmtDepthStencil) || (D3DFMT_D24X4S4 == combo->fmtDepthStencil) || (D3DFMT_D16 == combo->fmtDepthStencil) || (D3DFMT_D15S1 == combo->fmtDepthStencil)) { m_Stencil = true; } else { m_Stencil = false; } // Check windowed mode if (m_Windowed) { D3DdeviceInfo.D3Dparams.hDeviceWindow = m_hRenderWnd[0]; D3DdeviceInfo.D3Dparams.BackBufferWidth = m_ScreenWidth; D3DdeviceInfo.D3Dparams.BackBufferHeight = m_ScreenHeight; } else { D3DdeviceInfo.D3Dparams.hDeviceWindow = m_hMainWindow; D3DdeviceInfo.D3Dparams.BackBufferWidth = D3DdeviceInfo.DisplayMode.Width; D3DdeviceInfo.D3Dparams.BackBufferHeight = D3DdeviceInfo.DisplayMode.Height; } // Create the Direct3D device if (NULL == m_D3Dsystem->CreateDevice (device->nAdapter, device->D3DDevType, D3DdeviceInfo.D3Dparams.hDeviceWindow, combo->Behaviour, &D3DdeviceInfo.D3Dparams, &m_D3Ddevice)) { throw Exception ("D3Dgraphics::StartGraphics", __LINE__, ::GetLastError(), "Main Graphics Device NOT Created"); } // Create additional swap chains if required and possible if (m_Windowed && (m_hRenderWnd.size() > 1)) { m_D3Dchains = new LPDIRECT3DSWAPCHAIN[m_hRenderWnd.size()]; for (UINT i = 0; i < m_hRenderWnd.size(); i++) { D3DdeviceInfo.D3Dparams.BackBufferWidth = 0; D3DdeviceInfo.D3Dparams.BackBufferHeight = 0; D3DdeviceInfo.D3Dparams.hDeviceWindow = m_hRenderWnd[i]; m_D3Dchains[i] = NULL; if (NULL == m_D3Ddevice->CreateAdditionalSwapChain (&D3DdeviceInfo.D3Dparams, &(m_D3Dchains[i]))) { int error = ::GetLastError(); std::stringstream os; os << "Additional Graphics Device #" << i <<" NOT Created" << std::ends; throw Exception ("D3Dgraphics::StartGraphics", __LINE__, error, (char *)os.str().c_str()); } } } // Clean Up Enumeration delete m_D3Denum; m_D3Denum = NULL; return SUCCESS; }
  10. OpenGL

    Not quite: First I save the current status of blending: // Blending the ring, Save some settings BlendEnabled = glIsEnabled (GL_BLEND); Then I set the options I want (whatever the current status!): // Options to blend the ring drawing glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); Do my rendering.... and last restore the blending to its value at the beginning: // Restore saved settings if (BlendEnabled) { } else { glDisable (GL_BLEND); } OK! the last if could have been coded as: // Restore saved settings if (!BlendEnabled) { glDisable (GL_BLEND); } I always do the same thing when I want to use a global variable: (1) save the current value (2) Set it to whatever I want and use it. At that point I do not care what its setting was before, I am just concerned about my current needs, (3) Restore the initial value so other part of the program are not affected by what I did.
  11. OpenGL

    I added to the code the beginning of the drawing control function. There is a glClear statement at the beginning that clear colour, depth and stencil buffers.
  12. OpenGL

    Nope, blending is always done when drawing the ring, during the first rendering (depth tagging) and the last two (without and with lights on). But the ring drawing is done AFTER the planet has been drawn (it is a child node of the planet). I tried doing the blending only on the last rendering with lights on, but got the same results.
  13. Hi! I am new at OpenGL and using Glut under Windows, I wrote in C my first program. It is a simulation of the solar system (1.25MB!) and it is working fine... I am now trying to introduce shadows using shadow volumes. It seems to work OK, except that I lost the blending effect for transparency of the ring for the planets that have rings, such as Saturn. Any help to get the correct rendering would be much appreciated... Here is what I get (source code extracts follow): (1) No shadows, transparency OK: (2) With Shadows, transparency gone: Here is the code: (1) The main section that control the rendering: [Sourcelang="c"] /************************************************************************/ /* */ /* Solar system functions: Draw. */ /* */ /************************************************************************/ GLvoid DrawSolarSystem (GLdouble XX, GLdouble YY, GLdouble ZZ, GLdouble Omega) { TreeNODE *Node = &_SolarSystem; if (Picking) { glInitNames (); glPushName (0); } else { cOrient = Omega; if (Zoom < 0) { cX = XX; cY = YY; cZ = ZZ; } else { Sphere2Cartesian (XX, YY, ZZ, &cX, &cY, &cZ); } /* endif */ } /* endif */ // Clear The Screen And The Depth Buffer glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); Shadowing = FALSE; if (Zoom < 0) { // Full System drawing glTranslatef (cX, cY, cZ); glRotatef (cOrient, 1.0, 0.0, 0.5); glLightfv (GL_LIGHT0, GL_POSITION, Light0_Position); glStencilFunc (GL_ALWAYS, 0x01, 0x01); glStencilOp (GL_KEEP, GL_KEEP, GL_REPLACE); DrawShadows = FALSE; DrawSun (); DrawTreeNode (NULL, Node->Sibling, TRUE); DrawTreeNode (NULL, Node->Child, TRUE); } else { // Drawing of selected subsystem gluLookAt (cX, cY, cZ, 0.0, 0.0, 0.0, 0.0, cOrient, 0.0); ZoomToPlanet (-1); glLightfv (GL_LIGHT0, GL_POSITION, Light0_Position); DrawSun (); if (Zoom > 0) { if ((DrawShadows == FALSE) || (Picking == TRUE)) { // Stencil function for background iimage glStencilFunc (GL_ALWAYS, 0x01, 0x01); glStencilOp (GL_KEEP, GL_KEEP, GL_REPLACE); do { if (Node->Properties == Properties[Zoom]) { // Draw the selected node and its childs without shadowing DrawTreeNode (NULL, Node, FALSE); DrawTreeNode (NULL, Node->Child, TRUE); // to exit loop Node = NULL; } else { // Skip to next node Node = Node->Sibling; } /* endif */ } while (Node != NULL); /* enddo */ } else { do { if (Node->Properties == Properties[Zoom]) { if (Node->Child != NULL) { //Draw the selected node with shadowing Shadowing = FALSE; glColorMask (GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); DrawTreeNode (NULL, Node, FALSE); // Render scene in depth buffer // Draw Shadow volume Shadowing = TRUE; glEnable (GL_STENCIL_TEST); // Render shadow volume in stencil buffer glDepthMask (GL_FALSE); // Keep Depth buffer as is! glStencilFunc (GL_ALWAYS, 0, 1); // First Pass glStencilOp (GL_KEEP, GL_KEEP, GL_INCR); glCullFace (GL_BACK ); // Increment using front face of shadow volume DrawTreeNode (NULL, Node, FALSE); // Draw shadow volume // Second Pass glStencilOp (GL_KEEP, GL_KEEP, GL_DECR); glCullFace (GL_FRONT); // Decrement using back face of shadow volume DrawTreeNode (NULL, Node, FALSE); // Draw Shadow volume // Now Draw the Scene glDepthMask (GL_TRUE); glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glDepthFunc (GL_LEQUAL); glCullFace (GL_BACK); glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP); Shadowing = FALSE; glStencilFunc (GL_EQUAL, 0, 1); // Draw shadowed parts glDisable (GL_LIGHT0); DrawTreeNode (NULL, Node, FALSE); glStencilFunc (GL_EQUAL, 1, 1); // Draw lighted parts glEnable (GL_LIGHT0); DrawTreeNode (NULL, Node, FALSE); } else { // No child node to receive shadow ShadowBlend = TRUE; DrawTreeNode (NULL, Node, FALSE); } /* endif */ // Stencil functionfor background image glColorMask (GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); glDepthFunc (GL_LESS); glClear (GL_STENCIL_BUFFER_BIT); glStencilFunc (GL_ALWAYS, 0x01, 0x01); glStencilOp (GL_KEEP, GL_KEEP, GL_REPLACE); DrawTreeNode (NULL, Node, FALSE); glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // To exit loop Node = NULL; } else { //Skip to next node Node = Node->Sibling; } /* endif */ } while (Node != NULL); /* enddo */ } /* endif */ } /* endif */ } /* endif */ (2) The drawing tree with the shadow rendering code: /************************************************************************/ /* */ /* Walk Tree to Draw the System. */ /* */ /************************************************************************/ static GLvoid DrawTreeNode (PROPERTIES *Parent, TreeNODE *Planet, BOOL Loop) { if (Planet != NULL) { glPushMatrix (); glLoadName ((GLuint) Planet); if (Planet->DrawModel != NULL) { Planet->DrawModel (); } else { if (RING == Planet->Type) { if (!Shadowing) { DrawRing (Parent, (ASPECTS *) Planet->Properties); } else { } /* endif */ } else { DrawOrbit (Planet->Properties, Parent, Planet); if (Planet->Type != NODE) { // Draw shadow only if not a node if ((DrawShadows == TRUE) && (Picking == FALSE)) { if (Shadowing) { DrawShadow (Planet->Properties, Parent, Planet); } else { } /* endif */ } /* endif */ if (!Shadowing) { DrawPlanet (Planet->Properties, Parent); } else { } /* endif */ } else { DrawPlanet (Planet->Properties, Parent); } /* endif */ } /* endif */ } /* endif */ DrawTreeNode (Planet->Properties, Planet->Child, TRUE); glPopMatrix (); if (Loop) { DrawTreeNode (Parent, Planet->Sibling, Loop); } else { } /* endif */ } else { } /* endif */ return; } /************************************************************************/ /* */ /* Draw the shadow volume of a planet or satellite. */ /* */ /************************************************************************/ GLvoid DrawShadow (PROPERTIES *Planet, PROPERTIES *Parent, TreeNODE *Node) { fprintf (stdout, "Drawing the shadow for %s", Node->Name); glPushMatrix (); glDisable (GL_LIGHTING); if (Node->Type == PLANET) { if (Planet->ListShadow != 0) { glRotated (-Planet->Orbit_Angle, 0.0, 1.0, 0.0); glCallList ( Planet->ListShadow); } else { } /* endif */ } else { if (Node->Type == SATELLITE) { } else { } /* endif */ } /* endif */ glEnable (GL_LIGHTING); glPopMatrix (); return; } (3) The ring rendering code: /************************************************************************/ /* */ /* Draw the rings for a planet or satellite. */ /* */ /************************************************************************/ GLvoid DrawRing (PROPERTIES *Planet, ASPECTS *Ring) { glPushMatrix (); // Blending the ring, Save some settings BlendEnabled = glIsEnabled (GL_BLEND); // Options to blend the ring drawing glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); if (Ring->ListNumber != 0) { if (Ring->TexName != 0) { glMaterialf (GL_FRONT, GL_SHININESS, Ring->Shininess); glCallList (WhiteLightList); glEnable (GL_TEXTURE_2D); glBindTexture (GL_TEXTURE_2D, Ring->TexName); glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glCallList (Ring->ListNumber); glDisable (GL_TEXTURE_2D); } else { glCallList (Ring->ListNumber); } /* endif */ } else { DrawFlatRing (Ring->Outer, Ring->Width / Ring->Outer, Ring->Height); } /* endif */ // Restore saved settings if (BlendEnabled) { } else { glDisable (GL_BLEND); } /* endif */ glPopMatrix (); return; } [Edited by - LeLorrain on December 27, 2006 1:30:58 PM]
  14. Hi! I am relativvly new at C++, although I understand OOP coming from other languages (Macromedia ActionScript and PHP). I downloaded the program NeHeGL_oop.zip and tried to adapt it to an MVC paradigm. Although I simplified the code because it is using some C++ coding features that I do not yet fully understand, I was able to have a working program... until I made a simple change! Noe the program fail on an Access Violation in the module STRLEN.ASM (according to Visual Studio v6) while creating this class instance: /************************************************** * * Window definition * **************************************************/ WinBase::WinBase (WinClass * winClass) : m_hWnd (NULL), m_pClass (winClass), m_Exstyle (NULL), // extended window style m_pTitle (NULL), // pointer to window name m_style (NULL), // window style m_x (CW_USEDEFAULT), // horizontal position of window m_y (CW_USEDEFAULT), // vertical position of window m_width (CW_USEDEFAULT), // window width m_height (CW_USEDEFAULT), // window height m_hWndParent (HWND_DESKTOP), // handle to parent or owner window m_hMenu (NULL) // handle to menu, or child-window identifier { m_pDebug = new WinDebug ("GL_Windows", MY_DEBUG); m_pDebug->Toggle (); // Activate Debug display return; } I put the whole program on http://rene.dalle.ca/projects/GLapplication.rar ready to be re-compiled with Visual Studio. There is a break defined just at the entry to the class constructor (in GL_Windows.cpp) and if I hit the F10 key, I immediately get the exception ("First-chance exception in GLapplication.exe: 0xC0000005: Access Violation.") with the debugger pointing into the STRLEN.ASM module! If anyone can tell me what I did wrong, I'll be in their debt for ever! Cheers.... RD OK! I found my mistake: m_pTitle (NULL) should have been m_pTitle ("") since I changed the definition from char * to std::string! Now it work fine again! [Edited by - LeLorrain on June 10, 2005 8:50:06 PM]