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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:09:25+00:00 2026-06-07T08:09:25+00:00

I made a painting program. Everything works as I expected. But while drawing, sometimes

  • 0

I made a painting program. Everything works as I expected. But while drawing, sometimes some strange things happen.

I run app, and press left mouse button on image. It should draw point from code:

glEnableClientState(GL_VERTEX_ARRAY);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, brushTextura);
glPointSize(100);
glVertexPointer(2, GL_FLOAT, 0,GLVertices);
glDrawArrays(GL_POINTS, 0, count);
glDisableClientState(GL_VERTEX_ARRAY);

at point where I press. mouseDown registers mouseDown location, converts it to NSValue, sends to array, and then before drawing I extract NSValue to CGPoint and send it to GLfloat so that it could be drawn by glDrawArrays. But no matter where I click the mouse on the image it draws the point at coordinates (0,0). After that every thing works OK. See image:

mouse click

This was first problem. The second problem is that when I paint with it (drag pressed mouse), sometimes points appear where they are not drawn. Image:

mouse drag

When I continue drag it disappears. After some dragging it appears again and disappears again. And so on. Image:

enter image description here

Any Ideas why it could happen? I will post code bellow:


Mouse down:

- (void) mouseDown:(NSEvent *)event
{
    location = [self convertPoint: [event locationInWindow] fromView:self];
    NSValue *locationValue = [NSValue valueWithPoint:location];
    [vertices addObject:locationValue];

        [self drawing];
}

Mouse dragged:

- (void) mouseDragged:(NSEvent *)event
{
    location = [self convertPoint: [event locationInWindow] fromView:self];
    NSValue *locationValue = [NSValue valueWithPoint:location];
    [vertices addObject:locationValue];

        [self drawing];
}

Drawing:

- (void) drawing {
int count = [vertices count] * 2;
NSLog(@"count: %d", count);
int currIndex = 0;
GLfloat *GLVertices = (GLfloat *)malloc(count * sizeof(GLfloat));
for (NSValue *locationValue in vertices) {
    CGPoint loc = locationValue.pointValue;
    GLVertices[currIndex++] = loc.x;
    GLVertices[currIndex++] = loc.y;    
 }
glEnableClientState(GL_VERTEX_ARRAY);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, brushTextura);
glPointSize(100);
glVertexPointer(2, GL_FLOAT, 0, GLVertices);
glDrawArrays(GL_POINTS, 0, count);
glDisableClientState(GL_VERTEX_ARRAY);
}
  • 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-07T08:09:27+00:00Added an answer on June 7, 2026 at 8:09 am

    You are setting your count variable (the one used in glDrawArrays) to [vertices count] * 2, which seems strange.

    The last argument to glDrawArrays is the number of vertices to draw, whereas in your code it seems you are setting it to double the number (maybe you thought it’s the number of floats?), which means you are just drawing rubbish after the first count vertices.

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

Sidebar

Related Questions

I have made a program that reads voltage and current values of some diode
Thank everyone for the help I have made some really good changes but now
Made this nice little loop for hiding and showing div's, works as a charm
Made a custom obj called Item with some string fields and one float. .h
I made a dll in c# but i need to export the functions. Is
I made a Web service in which I have a function to count some
I made myself a template for all JSPs in my webapp that keeps things
i made a program to convert lowercase strings to upper case like strupr(); in
I have made a program which is a small library operated via software. When
I have Perl program based on IO::Async , and it sometimes just exits after

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.