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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:15:53+00:00 2026-06-17T13:15:53+00:00

I want to render an NSString to a monochrome OpenGL texture. I found many

  • 0

I want to render an NSString to a monochrome OpenGL texture. I found many examples on how to to that on iOS, but I’m struggling to find a code snippet that works on OSX.

I know how to do the last bit, uploading a texture to the GPU, but how do I get the raw (8 bit per pixel) data?

  • 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-17T13:15:54+00:00Added an answer on June 17, 2026 at 1:15 pm

    Take a look at GLString.m in Apple’s Cocoa OpenGL code sample. You can easily modify it to generate a monochrome texture. The relevant modifications result in code that looks like so:

    NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL pixelsWide:frameSize.width pixelsHigh:frameSize.height
        bitsPerSample:8 samplesPerPixel:1 hasAlpha:NO isPlanar:NO colorSpaceName:NSDeviceWhiteColorSpace bitmapFormat:0 bytesPerRow:frameSize.width bitsPerPixel:8];
    
    NSGraphicsContext *context = [NSGraphicsContext graphicsContextWithBitmapImageRep:bitmap];
    [NSGraphicsContext saveGraphicsState];
    [NSGraphicsContext setCurrentContext:context];
    
    …    
    
    [string drawAtPoint:NSMakePoint(marginSize.width, marginSize.height)]; // draw at offset position
    
    …
    
    [NSGraphicsContext restoreGraphicsState];
    
    if (0 == texName)
        glGenTextures (1, &texName);
    
    glBindTexture (GL_TEXTURE_RECTANGLE_EXT, texName);
    glTexSubImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, 0, 0, texSize.width, texSize.height, GL_LUMINANCE, GL_UNSIGNED_BYTE, [bitmap bitmapData]);
    

    The key parts are:

    1. Allocate your own NSBitmapImageRep with the desired format.
    2. Allocate an NSGraphicsContext that writes in to your NSBitmapImageRep.
    3. Draw your string.
    4. Restore the graphics context to its original state.
    5. Call glTexSubImage2D with a pixel format that is compatible with the format you initialized your NSBitmapImageRep to.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here my code rendering pdf is ok .But I don't want render directly save
I want to render a profile user container that contains a list of labels
I got a problem with UIWebView. I want to render my own html code
First I want render code is: ul li a the render result should be
i want to render an action from another controller, but i get the error:
I want to render particles with hexagons that fade out to the outside. I've
I want to render in a template an image that originates from a ClientBundle.
I want to render an orthographic projection into texture. The rendering of the mesh
I want to render color gradient that start from one side to another. In
I want to render a scene interactively. The controls are already provided so that

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.