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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:08:01+00:00 2026-06-10T05:08:01+00:00

What am doing wrong ? I am trying to learn OpenGL and Objective-C, i

  • 0

What am doing wrong ?
I am trying to learn OpenGL and Objective-C, i am porting it code from C to Objective-C.

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <GL/glew.h>
#include <GL/freeglut.h>
#define WINDOW_TITLE_PREFIX "Chapter 1"

int CurrentWidth = 800,
    CurrentHeight = 600,
    WindowHandle = 0;

void Initialize(int, char*[]);
void InitWindow(int, char*[]);
void ResizeFunction(int, int);
void RenderFunction(void);

int main(int argc, char* argv[])
{
    Initialize(argc, argv);

    glutMainLoop();

    exit(EXIT_SUCCESS);
}

void Initialize(int argc, char* argv[])
{
    InitWindow(argc, argv);

    fprintf(
        stdout,
        "INFO: OpenGL Version: %s\n",
        glGetString(GL_VERSION)
    );

    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
}

void InitWindow(int argc, char* argv[])
{
    glutInit(&argc, argv);

    glutInitContextVersion(4, 0);
    glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);
    glutInitContextProfile(GLUT_CORE_PROFILE);

    glutSetOption(
        GLUT_ACTION_ON_WINDOW_CLOSE,
        GLUT_ACTION_GLUTMAINLOOP_RETURNS
    );

    glutInitWindowSize(CurrentWidth, CurrentHeight);

    glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);

    WindowHandle = glutCreateWindow(WINDOW_TITLE_PREFIX);

    if(WindowHandle < 1) {
        fprintf(
            stderr,
            "ERROR: Could not create a new rendering window.\n"
        );
        exit(EXIT_FAILURE);
    }

    glutReshapeFunc(ResizeFunction);
    glutDisplayFunc(RenderFunction);
}

void ResizeFunction(int Width, int Height)
{
    CurrentWidth = Width;
    CurrentHeight = Height;
    glViewport(0, 0, CurrentWidth, CurrentHeight);
}

void RenderFunction(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glutSwapBuffers();
    glutPostRedisplay();
}

I got this code from http://openglbook.com/the-book/chapter-1-getting-started/

I’ve done this but i am no realy sure what is the error i think the problem is with pointers.

header.h

#import <Foundation/Foundation.h>
#import <stdio.h>
#import <string.h>
#import <GL/glew.h>
#import <GL/freeglut.h>
#define WINDOW_TITLE_PREFIX "test gl objective c"

@interface princ : NSObject {
    int CurrentWidth;
    int CurrentHeight;
    int WindowHandle;

}

-(void)InitValues;
-(void)ResizeFunction;
-(void)RenderFunction;
-(void)InitWindow: (int)argc: (char*[])argv:(void*)FoundRZ:(void*)FoundRD;
-(void)Initialize: (int)argc: (char*[])argv;

@end

@implementation princ 

-(void)InitValues {

    CurrentWidth = 800;
    CurrentHeight = 600;
    WindowHandle = 0;
}

-(void)ResizeFunction {

    int Width = 0;
    int Height = 0;
    CurrentWidth = Width;
    CurrentHeight = Height;
    glViewport(0, 0, CurrentWidth, CurrentHeight);

}

-(void)RenderFunction { 

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glutSwapBuffers();
    glutPostRedisplay();


    }

-(void)InitWindow: (int)argc: (char*[])argv:(void*)FoundRZ:(void*)FoundRD {

    glutInit(&argc, argv);

    glutInitContextVersion(4, 0);
    glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);
    glutInitContextProfile(GLUT_CORE_PROFILE);

    glutSetOption ( 
      GLUT_ACTION_ON_WINDOW_CLOSE,
      GLUT_ACTION_GLUTMAINLOOP_RETURNS
    );

    glutInitWindowSize(CurrentWidth, CurrentHeight);
    WindowHandle = glutCreateWindow(WINDOW_TITLE_PREFIX);

    if(WindowHandle < 1) {
        fprintf(
              stderr, "ERROR: Could not create a new rendering window.\n" 
              );
        exit(EXIT_FAILURE);
    }

    glutReshapeFunc(FoundRZ);
    glutDisplayFunc(FoundRD);


    }

-(void)Initialize: (int)argc: (char*[])argv {


    fprintf(stdout, "INFO: OpenGL Version: %s\n", glGetString(GL_VERSION));




}


@end

1.m

#import "header.h"

int main (int argc, char *argv[]) {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    NSLog(@"hello");


    princ *GLMAIN = [[princ alloc] init];

    [GLMAIN InitValues];
    [GLMAIN InitWindow:argc:argv:[GLMAIN ResizeFunction]:[GLMAIN RenderFunction]];
    [GLMAIN Initialize:argc:argv];

    [pool drain];
    return 0;


}

Error :

$ clang -ObjC 1.m -o 1  `gnustep-config --objc-flags` -I/usr/local/lib/gcc42/gcc/x86_64-portbld-freebsd9.0/4.2.5/include -fconstant-string-class=NSConstantString  -I/usr/local/GNUstep/System/Library/Headers -L/usr/local/GNUstep/System/Library/Libraries -L/usr/local/lib -lgnustep-base -I/usr/local/include -L/usr/local/lib -lglut -lGL
1.m:12:31: error: sending 'void' to parameter of incompatible type 'void *';
        [GLMAIN InitWindow:argc:argv:[GLMAIN ResizeFunction]:[GLMAIN RenderFunction]];
                                     ^~~~~~~~~~~~~~~~~~~~~~~
./header.h:18:52: note: passing argument to parameter 'FoundRZ' here
-(void)InitWindow: (int)argc: (char*[])argv:(void*)FoundRZ:(void*)FoundRD;
                                                   ^
1.m:12:55: error: sending 'void' to parameter of incompatible type 'void *';
        [GLMAIN InitWindow:argc:argv:[GLMAIN ResizeFunction]:[GLMAIN RenderFunction]];
                                                             ^~~~~~~~~~~~~~~~~~~~~~~
./header.h:18:67: note: passing argument to parameter 'FoundRD' here
-(void)InitWindow: (int)argc: (char*[])argv:(void*)FoundRZ:(void*)FoundRD;
                                                                  ^
2 errors generated.

I am not using mac i am using FreeBSD but i have hope any apple developer can help with this little problem.

  • 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-10T05:08:02+00:00Added an answer on June 10, 2026 at 5:08 am

    I think it’s your initWindow method. You’re passing a method that returns void to an argument that takes a void*. The main problem here is that glut doesn’t support Objective-C method calling, and requires C functions instead, so change your resizeFunction and renderFunction to C functions, then pass it and it should work.

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

Sidebar

Related Questions

I don't get what I'm doing wrong. I'm trying to populate a form from
My code below won't compile. What am i doing wrong? I'm basically trying to
What am I doing wrong? Im trying to send a email using c# with
What am I doing wrong here? I'm trying to get started with jQuery UI
What am I doing wrong here? Im trying to save a canvas drawing by
I don't know what I'm doing wrong but I've been trying to get this
I'm trying to free g_strdup but I'm not sure what I'm doing wrong. Using
QUESTION: What am I missing or doing wrong? I'm trying to migrate fully functional
I have spent the last hour trying to see what I'm doing wrong, or
Someone has to be able to explain what I'm doing wrong here! I'm trying

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.