Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8042771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:41:54+00:00 2026-06-05T04:41:54+00:00

When you create points using three dimensions for each point and you use an

  • 0

When you create points using three dimensions for each point and you use an Ortho projection to view the points, would there be a reason that only the points on the -near surface would appear? For example, if you use (the SharpGL method) gl.Ortho(0, width, height, 0, -10, 10), only the points at z=10 (because the near surface is at -10) actually show up.

I’m currently using SharpGL – but I’m hoping the issue I’m having isn’t with that particular implementation/library.

EDIT: I’m adding the code below that demonstrates the issue. Note that this example requires SharpGL and is in fact a modification of a WPF sample project that comes with the current SharpGL source code (the original sample project is called TwoDSample).

The project requires a MainWindow.xaml and a MainWindow.xaml.cs. Here’s the xaml:

<Window x:Class="TwoDSample.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525"
    xmlns:my="clr-namespace:SharpGL.WPF;assembly=SharpGL.WPF">
    <Grid>
        <my:OpenGLControl Name="openGLControl1" OpenGLDraw="openGLControl1_OpenGLDraw" OpenGLInitialized="openGLControl1_OpenGLInitialized"
                          Resized="openGLControl1_Resized"/>
    </Grid>
</Window>

Here is the code behind:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using SharpGL.Enumerations;

namespace TwoDSample
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        // NOTE: I use this to restrict the openGLControl1_OpenGLDraw method to 
        // drawing only once after m_drawCount is set to zero;
        int m_drawCount = 0;
        private void openGLControl1_OpenGLDraw(object sender,     SharpGL.SceneGraph.OpenGLEventArgs args)
        {
            // NOTE: Only draw once after m_drawCount is set to zero
            if (m_drawCount < 1)
            {
                //  Get the OpenGL instance.
                var gl = args.OpenGL;

                gl.Color(1f, 0f, 0f);
                gl.PointSize(2.0f);

                //  Draw 10000 random points.
                gl.Begin(BeginMode.Points);
                Random random = new Random();
                for (int i = 0; i < 10000; i++)
                {
                    double x = 10 + 400 * random.NextDouble();
                    double y = 10 + 400 * random.NextDouble();
                    double z = (double)random.Next(-10, 0);

                    // Color the point according to z value
                    gl.Color(0f, 0f, 1f);  // default to blue
                    if (z == -10)
                        gl.Color(1f, 0f, 0f);   // Red for z = -10
                    else if (z == -1)
                        gl.Color(0f, 1f, 0f);   // Green for z = -1

                    gl.Vertex(x, y, z);
                }

                    gl.End();
                    m_drawCount++;
                }
            }

            private void openGLControl1_OpenGLInitialized(object sender,     SharpGL.SceneGraph.OpenGLEventArgs args)
        {

        }

        private void openGLControl1_Resized(object sender,     SharpGL.SceneGraph.OpenGLEventArgs args)
        {
            // NOTE: force the draw routine to happen again when resize occurs
            m_drawCount = 0;
            //  Get the OpenGL instance.
            var gl = args.OpenGL;

            //  Create an orthographic projection.
            gl.MatrixMode(MatrixMode.Projection);
            gl.LoadIdentity();

            // NOTE: Basically no matter what I do, the only points I see are those at
            // the "near" surface (with z = -zNear)--in this case, I only see green points
            gl.Ortho(0, openGLControl1.ActualWidth, openGLControl1.ActualHeight, 0, 1, 10);

            //  Back to the modelview.
            gl.MatrixMode(MatrixMode.Modelview);
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T04:41:56+00:00Added an answer on June 5, 2026 at 4:41 am

    Thanks to MadcoreTom’s comment about the depth buffer and a bit of Googling, I think I found the (or at least “a”) solution. If I clear the depth buffer at the start of the drawing routine, (and color points red if z == -9 rather than z == -10 since random.Next(-10,0) will not give a value of -10), THEN things seem to work as expected.

    To see points at all z values (within the Ortho limits) I just replaced the openGlControl1_OpenGLDraw method to the following:

        private void openGLControl1_OpenGLDraw(object sender,     SharpGL.SceneGraph.OpenGLEventArgs args)
        {
            // NOTE: Only draw once after m_drawCount is set to zero
            if (m_drawCount < 1)
            {
                //  Get the OpenGL instance.
                var gl = args.OpenGL;
    
                // ADDED THIS LINE
                gl.Clear(SharpGL.OpenGL.GL_DEPTH_BUFFER_BIT);
    
                gl.Color(1f, 0f, 0f);
                gl.PointSize(2.0f);
    
                //  Draw 10000 random points.
                gl.Begin(BeginMode.Points);
                Random random = new Random();
                for (int i = 0; i < 10000; i++)
                {
                    double x = 10 + 400 * random.NextDouble();
                    double y = 10 + 400 * random.NextDouble();
                    double z = (double)random.Next(-10, 0);
    
                    // Color the point according to z value
                    gl.Color(0f, 0f, 1f);  // default to blue
                    if (z == -9)
                        gl.Color(1f, 0f, 0f);   // Red for z = -10
                    else if (z == -1)
                        gl.Color(0f, 1f, 0f);   // Green for z = -1
    
                    gl.Vertex(x, y, z);
                }
    
                    gl.End();
                    m_drawCount++;
                }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a polygon using points in xaml and as per
I am using following code to create new wifi access point and to connect
I want to create one virtualenv using another as the starting point, is this
i am using eclipse 3.5 to create a simple plugin bearing an extension point.
I'm writing an app that looks up points in two-dimensional space using a k-d
I would like to create an animation of an object using an elliptical path.
I am using Visual Studio 2008 and have added a web reference that points
I use Paperclip 2.3.11 in my Rails 3 application, and I create thumbnails using:
I'm using jQuery to create animations of an image object. I would like the
I'm finding that there are several points in the stored procedures that I'm creating

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.