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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:52:58+00:00 2026-06-02T00:52:58+00:00

I am creating a 2D openGL texture from an NSImage (cocoa desktop). I grabbed

  • 0

I am creating a 2D openGL texture from an NSImage (cocoa desktop).
I grabbed some code from the internet and it seems to work.

However, I started to insert calls to glGetError() here and there to track other rendering bugs, and thus I traced a GL_INVALID_ENUM error to the call mentioned above. As per the documentation on glTexParameteri, both GL_TEXTURE_2D and GL_TEXTURE_BORDER seem to be valid parameters…?

any clue?

this is the code:

- (void) createOpenGLTexture
{
[_openGLContext makeCurrentContext];


if (_textureID != 0) {
    glDeleteTextures(1, &_textureID);
    _textureID = 0;
}

NSSize imageSize = [_originalImage size];


// .............................................................
// Flip Image Vertically

NSImage* image = [[NSImage alloc] initWithSize:imageSize];


NSRect rect = NSMakeRect(0, 0, imageSize.width, imageSize.height);

[image lockFocus];

NSAffineTransform* transform = [NSAffineTransform transform];
[transform translateXBy:0 yBy:rect.size.height];
[transform scaleXBy:+1.0 yBy:-1.0];
[transform concat];
[_originalImage drawAtPoint:NSZeroPoint 
                   fromRect:rect 
                  operation:NSCompositeCopy 
                   fraction:1];
[image unlockFocus];


// Then we grab the raw bitmap data from the NSBitmapImageRep that is 
// the ‘source’ of an NSImage

NSBitmapImageRep* bitmap = [[NSBitmapImageRep alloc] initWithData:[image TIFFRepresentation]];
[image release];


GLenum   imageFormat = GL_RGBA;

imageSize = [bitmap size];  // Needed?

long sourceRowBytes = [bitmap bytesPerRow];

//  This SHOULD be enough but nope
GLubyte* sourcePic = (GLubyte*) [bitmap bitmapData];

//  We have to copy that raw data one row at a time….yay
GLubyte* pic = malloc( imageSize.height * sourceRowBytes );
GLuint  i;
GLuint intHeight = (GLuint) (imageSize.height);

for (i = 0; i < imageSize.height; i++) {
    memcpy(pic + (i * sourceRowBytes), 
           sourcePic + (( intHeight - i - 1 )*sourceRowBytes), 
           sourceRowBytes);
}

[bitmap release];

sourcePic = pic;


// .........................................................................
// Create the texture proper

glEnable(GL_TEXTURE_2D);
checkOpenGLError();

glEnable(GL_COLOR_MATERIAL);
checkOpenGLError();

glGenTextures (1, &_textureID);
checkOpenGLError();

glBindTexture (GL_TEXTURE_2D, _textureID);
checkOpenGLError();

glPixelStorei(GL_UNPACK_ALIGNMENT,1);
checkOpenGLError();

//  Here we set the basic properties such as how it looks when resized and if it's bordered
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BORDER, 0);
checkOpenGLError();

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
checkOpenGLError();

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
checkOpenGLError();

//  Not really necessary all the time but we can also define if it can be tiled (repeating)
//  Here GL_TEXTURE_WRAP_S = horizontal and GL_TEXTURE_WRAP_T = vertical
//  This defaults to GL_REPEAT so we're going to prevent that by using GL_CLAMP
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
checkOpenGLError();

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
checkOpenGLError();

//  And.....CREATE
glTexImage2D(GL_TEXTURE_2D, 
             0, 
             imageFormat, 
             rect.size.width, 
             rect.size.height, 
             0, 
             imageFormat, 
             GL_UNSIGNED_BYTE, 
             sourcePic);
checkOpenGLError();

glDisable(GL_TEXTURE_2D);
checkOpenGLError();

glDisable(GL_COLOR_MATERIAL);

checkOpenGLError();
}
  • 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-02T00:53:00+00:00Added an answer on June 2, 2026 at 12:53 am

    GL_TEXTURE_BORDER is not a valid enum for glTexParameter(). Reference: http://www.opengl.org/sdk/docs/man/xhtml/glTexParameter.xml

    You cannot (and don’t need to) specify the bordersize. GL_TEXTURE_BORDER is only a valid enum for glGetTexLevelParameter() to retrieve the bordersize the opengl driver assigned to a specific texture level. As far as I am aware this is not used any more and the function returns 0 on all newer systems.

    Don’t confuse it with GL_TEXTURE_BORDER_COLOR which is used to set the color rendered when using the GL_CLAMP_BORDER wrapping mode.

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

Sidebar

Related Questions

I'm creating an Android app utilising OpenGL ES, and need some help with the
I am creating an OpenGL texture like this: glGenTextures( 1, &boardTex ); glBindTexture( GL_TEXTURE_2D,
I'm having a problem with texturing objects in OpenGL using texture atlases, I'm creating
I'm creating an application that need a nice GUI and some openGL rendering (I
I am creating an android game using opengl and a cocos2d port (http://code.google.com/p/cocos2d-android-1). I
I try to learn OpenGL by creating some sort of 3D Modeler application using
I am creating a point sprite texture program in opengl es 2.0 I remember
I am creating a simple opengl application which obviously includes some 3d-objects and textures.
I´m creating an opengl ES project and I´m trying to show some textures, all
I am creating a polygon filled with texture using opengl in cocos2d framework. I

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.