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

  • Home
  • SEARCH
  • 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 4622722
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:53:01+00:00 2026-05-22T02:53:01+00:00

Please help me to set a background image in EaglView. Here my source code

  • 0

enter image description herePlease help me to set a background image in EaglView. Here my source code with the image:

    glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
            brushImage = [UIImage imageNamed:@"Particle.png"].CGImage;
    width = CGImageGetWidth(brushImage);
    height = CGImageGetHeight(brushImage);
    if(brushImage) {
        brushData = (GLubyte *) calloc(width * height * 4, sizeof(GLubyte));
        brushContext = CGBitmapContextCreate(brushData, width, height, 8, width * 4, CGImageGetColorSpace(brushImage), kCGImageAlphaPremultipliedLast);
        CGContextDrawImage(brushContext, CGRectMake(0.0, 0.0, (CGFloat)width, (CGFloat)height), brushImage);
        CGContextRelease(brushContext);
        glGenTextures(1, &brushTexture);
        glBindTexture(GL_TEXTURE_2D, brushTexture);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, brushData);
        free(brushData);
    }
    self.contentScaleFactor = 1.0;
    glLoadIdentity();
    glMatrixMode(GL_PROJECTION);
    CGRect frame = self.bounds;
    CGFloat scale = self.contentScaleFactor;
    glOrthof(0, frame.size.width * scale, 0, frame.size.height * scale, -1, 1);
    glViewport(0, 0, frame.size.width * scale, frame.size.height * scale);
    glMatrixMode(GL_MODELVIEW);
    glDisable(GL_DITHER);
    glEnable(GL_TEXTURE_2D);
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnable(GL_BLEND);
    glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_POINT_SPRITE_OES);
    glTexEnvf(GL_POINT_SPRITE_OES, GL_COORD_REPLACE_OES, GL_TRUE);
    glPointSize(width / kBrushScale);`
  • 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-05-22T02:53:03+00:00Added an answer on May 22, 2026 at 2:53 am

    Instead of using a point sprite should simply draw a textured quad.

    GLfloat vert_tex[] = {
        0., 0.,
        1., 0.,
        1., 1.,
        0., 1.
    };
    
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glVertexPointer(2, GL_FLOAT, 0, vert_tex);
    glTexCoordPointer(2, GL_FLOAT, 0, vert_tex);
    
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, 1, 0, 1, -1, 1);
    
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, texture_name);
    
    glDrawArrays(GL_QUADS, 0, 4);
    

    EDIT2:

    // Erases the screen
    - (void) erase
    {
        [EAGLContext setCurrentContext:context];
    
        CGRect frame = self.bounds;
        CGFloat scale = self.contentScaleFactor;
    
        GLfloat vert_tex[] = {
            0., 0.,
            frame.size.width * scale, 0.,
            frame.size.width * scale, frame.size.height * scale,
            0., frame.size.height * scale
        };
    
        glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
    
        glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_TEXTURE_COORD_ARRAY);
        glVertexPointer(2, GL_FLOAT, 0, vert_tex);
        glTexCoordPointer(2, GL_FLOAT, 0, vert_tex);
    
        // Setup the view port in Pixels
        glMatrixMode(GL_PROJECTION);
        glOrthof(0, frame.size.width * scale, 0, frame.size.height * scale, -1, 1);
        glViewport(0, 0, frame.size.width * scale, frame.size.height * scale);
    
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
    
        glDisable(GL_DITHER);    
        glEnable(GL_TEXTURE_2D);
    
        // background_image texture must be initialized with the desired
        // content; see initWithCoder of original GLPaint example for
        // example code how to load textures.
        glBindTexture(GL_TEXTURE_2D, background_image);
    
        // Clear the buffer with background image    
        glDrawArrays(GL_QUADS, 0, 4);
    
        // Display the buffer
        glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
        [context presentRenderbuffer:GL_RENDERBUFFER_OES];
    
    }
    

    In renderLineFromPoint you must add a line to bind the brush texture before drawing:

    // Drawings a line onscreen based on where the user touches
    - (void) renderLineFromPoint:(CGPoint)start toPoint:(CGPoint)end
    {
         /* ... */
    
    
         // add this line here v v v v v v v v v v v
         glBindTexture(GL_TEXURE_2D, brushTexture);
         // ^ ^ ^ ^^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
    
         // Render the vertex array
         glVertexPointer(2, GL_FLOAT, 0, vertexBuffer);
         glDrawArrays(GL_POINTS, 0, vertexCount);
    
         // Display the buffer
         glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
         [context presentRenderbuffer:GL_RENDERBUFFER_OES];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please help me, how to set a background image for screen and How to
When I set repeating background image to a UITableView by using the following code
please help me to style this list , I need to set different background
Can anyone help me out please? I'm confused. I want to set up my
Please help! Background info I have a WPF application which accesses a SQL Server
Please help, I am stuck here --- irb> a = line of text\n line
i have an image sized 768X1024 and when i set the background image to
Can you please tell me how can I place an background image to a
I have a button connected to an action. When I set the background image
here ia an application where i displaying some text with image background but it

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.