Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 22 Mar 2013
Offline Last Active Oct 03 2013 12:56 PM

Posts I've Made

In Topic: Drawing text in interface that gets clipped at the end of the interfacewindow

03 October 2013 - 12:32 AM

Hi COlumbo,


great thanks thats exactly what I was looking for :)


Maybe I'll post my Interface solution when I finished it.

In Topic: Texture Mapping on Mac OS X doesn't work

29 May 2013 - 01:27 AM

Many thanks for your answers Dave and patrrr,


It was a result of many thinks that are different from cocoa and glut.


First I had to call the makeCurrentContext for the NSOpenglContext which set up the Context.

I somehow had to call it explicitly.


And another reason was that glut get(GLUT_WINDOW_WIDTH) and the corresponding GLUT_WINDOW_HEIGHT didn't work under cocoa.

they both returned 0. I set up my interface using the width and height of the window to make it more smooth.

And cause they both returned 0 my glviewport for the interface was set to 0,0,0,0. :(


Terrible mistake sorry for wasting you time :)


But thanks to your replies i figured it out Tanks!! :)

In Topic: Texture Mapping on Mac OS X doesn't work

28 May 2013 - 02:10 AM

Thanks for your answer.


The code for loading textures is as follows:

-(BOOL)loadTexture:(NSString *)_name {
    if ([_name isEqualToString:@""]) {
        return NO;
    NSString *substring = [_name substringFromIndex:_name.length-4];
    if ([substring isNotEqualTo:@".JPG"] && [substring isNotEqualTo:@".jpg"] && [substring isNotEqualTo:@".png"]) {
        return NO;
    NSBundle *bundle = [NSBundle mainBundle];
    NSString *path = bundle.bundlePath;
    path = [NSString stringWithFormat:@"%@/Contents/Resources/%@",path,_name];

    NSImage *image = [[NSImage alloc] initWithContentsOfFile:path];
    if (image == nil) {
        return NO;
    NSRect bigRect;
    bigRect.origin = NSZeroPoint;
    bigRect.size = [image size];
    [image lockFocus];
    NSBitmapImageRep *upsideDown = [[NSBitmapImageRep alloc] initWithFocusedViewRect: bigRect];
    [image unlockFocus];
    // since OpenGL draws images upside down, we need to flip this image along
    // the y axis. I know a cool trick for doing this when texture mapping,
    // but I want something a little more general for now
    NSInteger bytesPerRow = [upsideDown bytesPerRow];
    NSInteger bitsPerPixel = [upsideDown bitsPerPixel];
    BOOL hasAlpha = [upsideDown hasAlpha];
    NSInteger height = (int)bigRect.size.height;
    NSBitmapImageRep *_imageRep = [[NSBitmapImageRep alloc]
                 bitsPerSample:[upsideDown bitsPerSample]
                 samplesPerPixel:[upsideDown samplesPerPixel]
                 isPlanar:[upsideDown isPlanar]
    unsigned char *from = [upsideDown bitmapData];
    unsigned char *to = [_imageRep bitmapData];
    for (int i = 0; i < height; i++) {
        bcopy((from + bytesPerRow + i), (to + bytesPerRow + (height - i - 1)), bytesPerRow);
    GLenum format;
    format = hasAlpha ? GL_RGBA : GL_RGB;
    GLuint _tex;
    glGenTextures(1, &_tex);
    glBindTexture(GL_TEXTURE_2D, _tex);
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    glPixelStorei(GL_UNPACK_ROW_LENGTH, (GLint)bytesPerRow / (bitsPerPixel >> 3));
    [image release];
    [upsideDown release];
    [_imageRep release];
    texturename[texturecount] = _name;
    [texturename[texturecount] retain];
    int *temp = malloc((texturecount*sizeof(int))+1*sizeof(int));
    for (int count = 0; count<texturecount; count++) {
        temp[count] = textureid[count];
    textureid = temp;
    textureid[texturecount] = _tex;
    texturecount ++;
    return YES;


It's a whole lot of Code I copied it from another thread.

It worked fine for my old app.


I have a class called TextureLoader which keeps all the information like texture name and the corresponding opengl name as an int.

When a texture is asked for it will beloaded by the TextureLoader

-(GLuint)textureidforTexturename:(NSString *)_name {
    for (int x = 0; x < texturecount; x++) {
        if ([texturename[x] isEqualToString:_name]) {
            return textureid[x];
    if ([self loadTexture:_name]) {
        return textureid[texturecount-1];
    else {
        printf("not found\n");
        return 0; 


So what I do at the start of my app is create a window and inside a NSOpenGLView.

when I just clear the buffer and draw on the right side of my screen it comes up yellow and red for example. So this works.


Tanks a lot :)

In Topic: OpenGL mouse handling

25 March 2013 - 08:29 AM

Ok now I got it fixed!


after glutwarppointer is called the mouse is suppressed for a short amount of time.

This also occurred using the CGWarpMouseCursorPosition function.


So these are not to be used in a game.


Instead use

CGEventRef event = CGEventCreateMouseEvent(Nil, kCGEventMouseMoved, CGPointMake(windowwidth/2, windowheight/2), 
CGEventPost(kCGHIDEventTap, event);


This moves the mouse to the middle without creating any interference.

In Topic: OpenGL mouse handling

24 March 2013 - 12:52 AM

Hi Danicco,


thanks a lot for your reply.


Trying to keep the mouse in the center of the screen seemed to be the best solution to me. But the camera wont move fluently anymore because the function glutwarppointer is called every time the mouse is moved.


But I got another idea after 3 months of thinking smile.png


Now the mouse jumps back to the center of the screen every time it reaches the edges.


My solution is as follows:


I got a class that controls the OpenGL device functions.

The class is called inside the glut function and given the parameters.

Heres the function prototype.

-(void)mousepassivenotion:(int)_x y:(int)_y;



Inside the class I save the old point of the mouse within 2 int variables.

When I move the mouse the old and new values are given to my camera class.

-(void)movetomousemotionx:(int)_x y:(int)_y xold:(int)_xold yold:(int)_yold {
    if (_xold-_x < 500) {
        NSLog(@"%d %d : %d %d",_x, _x, _xold, _yold);
        if (_xold > _x) {
            [self performSelectorOnMainThread:@selector(surroundviewpoint:) withObject:[NSNumber numberWithInt:(_xold-_x)
            /mousesensivity] waitUntilDone:YES];
        else if (_x > _xold) {
            [self performSelectorOnMainThread:@selector(surroundviewpoint:) withObject:[NSNumber numberWithInt:(_xold-_x)
            /mousesensivity] waitUntilDone:YES];
        if (_yold > _y) {
            [self performSelectorOnMainThread:@selector(overviewviewpoint:) withObject:[NSNumber numberWithInt:(_y-_yold)
            /mousesensivity] waitUntilDone:YES];
        else if (_yold < _y) {
            [self performSelectorOnMainThread:@selector(overviewviewpoint:) withObject:[NSNumber numberWithInt:(_y-_yold)
            /mousesensivity] waitUntilDone:YES];



In the first line i check if the difference between old and new is bigger than 500 in the horizontal(x) axis.

I may add the y-axis too. This is because after glutwarppointer the function glutpassivemotion is called and the difference is bigger than 500 and is ignored. Then I call my surroungviewpoint function with the rotation radius.

Heres my surroundviewpoint function.

-(void)surroundviewpoint:(NSNumber *)_rotation {
    glTranslated(0, 0, -distance);
    glRotated(-topdown, 1, 0, 0);
    glRotated(_rotation.floatValue, 0, 1, 0);
    glRotated(topdown, 1, 0, 0);
    glTranslated(0, 0, distance);
    glGetDoublev(GL_MODELVIEW_MATRIX, Systemmatrix);



So now the mouse is pointing at the center of the screen.

There is only one more point. When you turn the camera around and reach the edge you can notice for a second that the mouse is not moving.

So I tried calling my camera function manually after calling glutwarppointer and parameterize as the new point the center and as the old point the center minus the original difference.

int dif[2];
dif[0] = _x-x; //x is the old value
dif[1] = _y-y; //y is the old value
x = windowwidth/2-dif[0];
y = windowheight/2-dif[1];

glutWarpPointer(windowwidth, windowheight);

[camera movetomousemotionx:x+dif[0] y:y+dif[1] xold:x yold:y];

But still you can notice it.


Sorry for that much code but I wanted others to be able to solve the problem reading the post. smile.png