glGenTextures always sets '0'....

tmaeda
Unregistered
 
Post: #1
Hi.

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()?
Quote this message in a reply
Oldtimer
Posts: 832
Joined: 2002.09
Post: #2
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:

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. Smile
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #3
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.
Quote this message in a reply
tmaeda
Unregistered
 
Post: #4
>Fenris

How right you are!!
It's running.

Thank you , SO MUCH!!
Quote this message in a reply
tmaeda
Unregistered
 
Post: #5
>OneSadcookie
Thank you! Really enlightening.

Great Forum!
Quote this message in a reply
Post Reply