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 7716089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:32:57+00:00 2026-06-01T02:32:57+00:00

I use a NSOpenGLView. – (void)initGL { // Setup OpenGL states [[self openGLContext] makeCurrentContext];

  • 0

I use a NSOpenGLView.

- (void)initGL 
{
    // Setup OpenGL states 
    [[self openGLContext] makeCurrentContext];
    // Setup OpenGL states
    glMatrixMode(GL_PROJECTION);
    CGRect frame = self.bounds;

    // Setup the view port in Pixels
    glOrtho(0, frame.size.width, 0, frame.size.height, -1, 1);
    glViewport(0, 0, frame.size.width, frame.size.height);
    glMatrixMode(GL_MODELVIEW);

    glDisable(GL_DITHER);
    glEnable(GL_TEXTURE_2D);
    glEnableClientState(GL_VERTEX_ARRAY);

    glEnable(GL_BLEND);

    //glEnable(GL_LINE_SMOOTH);
    glEnable(GL_POINT_SMOOTH);

    glEnable(GL_POINT_SPRITE);
    glTexEnvf(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);

    self.pointSize = pointSizeForDrawing;
}

Framebuffer creation and binding.

- (BOOL)createFramebuffer
{
    //Generating two buffers
    glGenRenderbuffers( NumRenderbuffers, renderbuffer ); 

    glBindRenderbuffer( GL_RENDERBUFFER, renderbuffer[Color]); 
    glRenderbufferStorage( GL_RENDERBUFFER, GL_RGBA, self.bounds.size.width, self.bounds.size.height);

    glBindRenderbuffer( GL_RENDERBUFFER, renderbuffer[Depth] ); 
    glRenderbufferStorage( GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, self.bounds.size.width, self.bounds.size.height);

    //Generating framebuffer
    glGenFramebuffers( 1, &framebuffer ); 
    glBindFramebuffer( GL_DRAW_FRAMEBUFFER, framebuffer );

    glFramebufferRenderbuffer( GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbuffer[Color] );
    glFramebufferRenderbuffer( GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, renderbuffer[Depth] );
    glEnable( GL_DEPTH_TEST );

    if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
    {
        DLog(@"failed to make complete framebuffer object %x", glCheckFramebufferStatus(GL_FRAMEBUFFER));
        return NO;
}

    return YES;
}

Line rendering

- (void)renderLineFromPoint:(CGPoint)start ToPoint:(CGPoint)end
{
    GLsizei vertexCount = 0;
    DLog(@"start: %@ end %@", NSStringFromCGPoint(start), NSStringFromCGPoint(end));

    // Add points to the buffer so there are drawing points every X pixels
    int count = MAX(ceilf(sqrtf((end.x - start.x) * (end.x - start.x) + (end.y - start.y) * (end.y - start.y)) / brushPixelStep), 1);
    for(int i = 0; i < count; ++i) 
    {
        if(vertexCount == vertexMax) 
        {
            vertexMax = 2 * vertexMax;
            vertexBuffer = realloc(vertexBuffer, vertexMax * 2 * sizeof(GLfloat));
        }

        vertexBuffer[2 * vertexCount + 0] = start.x + (end.x - start.x) * ((GLfloat)i / (GLfloat)count);
        vertexBuffer[2 * vertexCount + 1] = start.y + (end.y - start.y) * ((GLfloat)i / (GLfloat)count);
        vertexCount += 1;
    }

    // Render the vertex array
    glBindFramebuffer( GL_DRAW_FRAMEBUFFER, framebuffer);

    glClear(GL_DEPTH_BUFFER_BIT);

    glVertexPointer(2, GL_FLOAT, 0, vertexBuffer);

    glDrawArrays(GL_POINTS, 0, vertexCount);

}

And finally display buffer

- (void)displayBuffer
{
    DLog(@"Display");
    glBindFramebuffer( GL_READ_FRAMEBUFFER, framebuffer ); 
    glBindFramebuffer( GL_DRAW_FRAMEBUFFER, 0 ); 
    glViewport(0, 0, self.bounds.size.width, self.bounds.size.height); 
    glBlitFramebuffer( 0, 0, self.bounds.size.width, self.bounds.size.height, 0, 0, self.bounds.size.width, self.bounds.size.height, GL_COLOR_BUFFER_BIT, GL_NEAREST );
    glSwapAPPLE();
}

It does not matter if I change line glDrawArrays(GL_POINTS, 0, vertexCount); to glDrawArrays(GL_POINTS, 0, 1);. The effect is still the same despite value of vertexCount different than 1. Any ideas?

  • 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-01T02:32:59+00:00Added an answer on June 1, 2026 at 2:32 am

    First possible problem:

    glVertexPointer(2, GL_FLOAT, 0, vertexBuffer);
    

    As I understand vertexBuffer is an array of structures. So the error could be that the third parameter is 0 but it should be the size of this structure. For example:

    CVertex3 v[3];
    ...
    glVertexPointer(3,GL_FLOAT,sizeof(CVertex3),v);
    

    Updated

    Second possible problem:

    try to remove glEnable(GL_DEPTH_TEST); it wouldn’t work properly but I think I have seen the similar situation in Internet

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There are several similar OpenGL operations when working with an NSOpenGLView: glFlush() [[self openGLContext]
I'm building an app for Mac OS 10.6 that will use OpenGL. I'd like
I have an old AGL-based OpenGL windowing system that I am updating to use
I have made a window with an NSOpenGLView that I am rendering openGL content
If I use a standard NSWindow to host a NSOpenGLView which extends for all
'''use Jython''' import shutil print dir(shutil) There is no, shutil.move, how does one move
Use case: A does something on his box and gots stuck. He asks B
Use case: 3rd party application wants to programatically monitor a text file being generated
Use case: user clicks the link on a webpage - boom! load of files
use LWP::Simple; use Parallel::ForkManager; @links=( [http://prdownloads.sourceforge.net/sweethome3d/SweetHome3D-2.1-windows.exe,SweetHome3D-2.1-windows.exe], [http://prdownloads.sourceforge.net/sweethome3d/SweetHome3D-2.1-macosx.dmg,SweetHome3D-2.1-macosx.dmg], [http://prdownloads.sourceforge.net/sweethome3d/SweetHome3DViewer-2.1.zip,SweetHome3DViewer-2.1.zip], ); # Max 30 processes for

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.