glGenTextures always sets '0'....
Hi.
My glGenTextures() doesn't give correct ids.
I can't get the reason for 3 days.
Please give some advices.
Should I call any special funcion before glGenTextures()?
My glGenTextures() doesn't give correct ids.
I can't get the reason for 3 days.
Please give some advices.
Quote:=========================
@interface MyOpenGLView : NSOpenGLView
{
...
GLuint mtexture[2];
...
}
@end
#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[] =
{
NSOpenGLPFANoRecovery,
NSOpenGLPFAAccelerated,
NSOpenGLPFADoubleBuffer,
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]);
....
}
@end
-----------Run Console--------------
GenTextures 0 , 0
Should I call any special funcion before glGenTextures()?
Hi and welcome to the forum! 
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:
This will perform your GL setup on the first frame, when you're guaranteed to have everything running.

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:
Code:
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.
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.

