iDevGames Forums
glGenTextures always sets '0'.... - Printable Version

+- iDevGames Forums (
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: glGenTextures always sets '0'.... (/thread-4672.html)

glGenTextures always sets '0'.... - tmaeda - Dec 28, 2005 03:10 AM


My glGenTextures() doesn't give correct ids.
I can't get the reason for 3 days.

Please give some advices.

@interface MyOpenGLView : NSOpenGLView
GLuint mtexture[2];

#import <OpenGL/OpenGL.h>
#import <OpenGL/gl.h>
#import <OpenGL/glu.h>
#include <GLUT/glut.h>

@implementation MyOpenGLView

- (id)initWithFrame:(NSRect) frameRect
NSLog(@"MyOpenGLView entering initWithFrame:"); // diagnostic

NSOpenGLPixelFormatAttribute myAttributes[] =
NSOpenGLPFAColorSize, (NSOpenGLPixelFormatAttribute) SL_COLOR_BUFFER_SIZE,
NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute) SL_DEPTH_BUFFER_SIZE,
NSOpenGLPFAStencilSize, (NSOpenGLPixelFormatAttribute) SL_STENCIL_BUFFER_SIZE,
NSOpenGLPFAAccumSize, (NSOpenGLPixelFormatAttribute) SL_ACCUM_BUFFER_SIZE,
(NSOpenGLPixelFormatAttribute) 0

NSOpenGLPixelFormat *myPixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:myAttributes];

return [super initWithFrame:frameRect pixelFormat:myPixelFormat];

- (void)awakeFromNib

glGenTextures(2,&mtexture[0]);@implementation MyOpenGLView

NSLog(@"GenTextures %d , %d" , mtexture[0],mtexture[1]);




-----------Run Console--------------

GenTextures 0 , 0

Should I call any special funcion before glGenTextures()?

glGenTextures always sets '0'.... - Fenris - Dec 28, 2005 03:21 AM

Hi and welcome to the forum! Smile
glGenTextures will return zero if there is no active GL context when you call them. Your init method is setup correctly, but when awakeFromNib is called, it isn't visible or "activated". If you can accept 10.3 as your baseline, you can override
-prepareOpenGL and do it there, but if not, you will have to come up with some other mechanism for doing your GL setup later. My suggestion is to do the following in drawRect:

static BOOL firstFrame = NO;
if (!firstFrame)
    [self myGLSetup];
    firstFrame =YES;

This will perform your GL setup on the first frame, when you're guaranteed to have everything running. Smile

glGenTextures always sets '0'.... - OneSadCookie - Dec 28, 2005 03:41 AM

In general, OpenGL calls will crash if there's no current context. You've just been unfortunate enough in this case to hit a situation where one doesn't.

glGenTextures always sets '0'.... - tmaeda - Dec 28, 2005 03:42 AM


How right you are!!
It's running.

Thank you , SO MUCH!!

glGenTextures always sets '0'.... - tmaeda - Dec 28, 2005 04:28 AM

Thank you! Really enlightening.

Great Forum!