Example #1
0
        public void BeginObject(string objectName)
        {
            if (modelRoot != null && currentObject == null)
            {
                throw new InvalidOperationException("Attempting to start a root object, when one was already created and finished.");
            }

            if (currentObjectHasOwnCommands)
            {
                throw new InvalidOperationException("Objects containing both own commands and nested objects are not allowed.");
            }

            // Create the display list and the tree node associated with the object
            int objectDisplayList = GL.GenLists(1);

            try
            {
                OpenGlModelObjectInformation        objectInfo = new OpenGlModelObjectInformation(objectName, objectDisplayList);
                Tree <OpenGlModelObjectInformation> objectNode = new Tree <OpenGlModelObjectInformation>(objectInfo);

                if (currentObject != null)
                {
                    // Add the new object node as a children of the current object
                    currentObject.Add(objectNode);
                }
                else // (modelRoot = null here)
                {
                    // First object being created, set it as the root node
                    modelRoot = objectNode;
                }

                // Set the new node as the current object and start its display list
                currentObject = objectNode;
                currentObjectHasOwnCommands = false;
            }
            catch
            {
                GL.DeleteLists(objectDisplayList, 1);
                throw;
            }
        }
Example #2
0
 /// <summary>
 /// Render the model at position "index" in OpenGL.
 /// </summary>
 public void CallDisplayList(OpenGlModelObjectInformation model)
 {
     GL.CallList(model.DisplayListIndex);
 }