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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:03:56+00:00 2026-05-20T15:03:56+00:00

// // This code was created by Jeff Molofee ’99 // // If you’ve

  • 0
//
// This code was created by Jeff Molofee '99
//
// If you've found this code useful, please let me know.
//
// Visit me at www.demonews.com/hosted/nehe
//
/**************************************************************/
// This code was ported to MacOS by Tony Parker.
//  I'd also appreciate it if you could drop me a line if you found
//  this code useful. 
// 
//  Tony Parker - asp@usc.edu
// 
// Have a nice day.

#include <stdio.h>          // Header File For Standard Input / Output
#include <stdarg.h>         // Header File For Variable Argument Routines
#include <string.h>         // Header File For String Management
#include <stdlib.h>
#include <OpenGL/gl.h>              // Header File For The OpenGL32 Library
#include <OpenGL/glu.h>         // Header File For The GLu32 Library
#include <GLUT/glut.h>          // Header File For The GLUT Library

// Constants -----------------------------------------------------------------

#define kWindowWidth    512
#define kWindowHeight   256

// Structures ----------------------------------------------------------------

typedef struct              // Create A Structure
{
    GLubyte *imageData;     // Image Data (Up To 32 Bits)
    GLuint  bpp;            // Image Color Depth In Bits Per Pixel.
    GLuint  width;          // Image Width
    GLuint  height;         // Image Height
    GLuint  texID;          // Texture ID Used To Select A Texture
} TextureImage;             // Structure Name

// Function Prototypes -------------------------------------------------------

GLvoid InitGL(GLvoid);
GLvoid DrawGLScene(GLvoid);
GLvoid ReSizeGLScene(int Width, int Height);
GLvoid Idle(GLvoid);
bool LoadTGA(TextureImage *texture, char *filename);
GLvoid LoadGLTextures(GLvoid);

// Global Variables ----------------------------------------------------------

TextureImage    texture[1];     // Texture Storage ( NEW )

GLfloat         xrot;           // X Rotation ( NEW )
GLfloat         yrot;           // Y Rotation ( NEW )
GLfloat         zrot;           // Z Rotation ( NEW )

// Main ----------------------------------------------------------------------

int main(int argc, char** argv)
{

    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    glutInitWindowSize(kWindowWidth, kWindowHeight); 
    glutInitWindowPosition (100, 100);
    glutCreateWindow (argv[0]);

    InitGL();

    glutDisplayFunc(DrawGLScene); 
    glutReshapeFunc(ReSizeGLScene);
    glutIdleFunc(Idle);

    xrot = 0;
    yrot = 0;       
    zrot = 0;

    glutMainLoop();

    return 0;
}

// InitGL --------------------------------------------------------------------

GLvoid InitGL(GLvoid)
{

    LoadGLTextures();                           // Load The Texture(s) ( NEW )
    glEnable(GL_TEXTURE_2D);                    // Enable Texture Mapping ( NEW )

    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);       // This Will Clear The Background Color To Black
    glClearDepth(1.0);                          // Enables Clearing Of The Depth Buffer
    glDepthFunc(GL_LESS);                       // The Type Of Depth Test To Do
    glEnable(GL_DEPTH_TEST);                    // Enables Depth Testing 
    glShadeModel(GL_SMOOTH);                    // Enables Smooth Color Shading

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();                           // Reset The Projection Matrix

    gluPerspective(45.0f, (GLfloat) kWindowWidth / (GLfloat) kWindowHeight, 0.1f, 100.0f);  
    // Calculate The Aspect Ratio Of The Window

    glMatrixMode(GL_MODELVIEW);

}

// Idle ----------------------------------------------------------------------

GLvoid Idle(GLvoid)
{
    xrot += 0.3f;           // X Axis Rotation
    yrot += 0.2f;           // Y Axis Rotation
    zrot += 0.4f;           // Z Axis Rotation

    glutPostRedisplay();
}

// DrawGLScene ---------------------------------------------------------------

GLvoid DrawGLScene(GLvoid)
{    
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    glTranslatef(0.0f,0.0f,-5.0f);

    glRotatef(xrot,1.0f,0.0f,0.0f);             // Rotate On The X Axis
    glRotatef(yrot,0.0f,1.0f,0.0f);             // Rotate On The Y Axis
    glRotatef(zrot,0.0f,0.0f,1.0f);             // Rotate On The Z Axis

    glBindTexture(GL_TEXTURE_2D, texture[0].texID);

    glBegin(GL_QUADS);
    // Front Face
    glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);  // Bottom Left Of The Texture and Quad
    glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);  // Bottom Right Of The Texture and Quad
    glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);  // Top Right Of The Texture and Quad
    glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);  // Top Left Of The Texture and Quad
    // Back Face
    glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);  // Bottom Right Of The Texture and Quad
    glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);  // Top Right Of The Texture and Quad
    glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);  // Top Left Of The Texture and Quad
    glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);  // Bottom Left Of The Texture and Quad
    // Top Face
    glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);  // Top Left Of The Texture and Quad
    glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,  1.0f,  1.0f);  // Bottom Left Of The Texture and Quad
    glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,  1.0f,  1.0f);  // Bottom Right Of The Texture and Quad
    glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);  // Top Right Of The Texture and Quad
    // Bottom Face
    glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);  // Top Right Of The Texture and Quad
    glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);  // Top Left Of The Texture and Quad
    glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);  // Bottom Left Of The Texture and Quad
    glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);  // Bottom Right Of The Texture and Quad
    // Right face
    glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);  // Bottom Right Of The Texture and Quad
    glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);  // Top Right Of The Texture and Quad
    glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);  // Top Left Of The Texture and Quad
    glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);  // Bottom Left Of The Texture and Quad
    // Left Face
    glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);  // Bottom Left Of The Texture and Quad
    glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);  // Bottom Right Of The Texture and Quad
    glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);  // Top Right Of The Texture and Quad
    glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);  // Top Left Of The Texture and Quad
    glEnd();



    glutSwapBuffers();
    glFlush();
}

// ReSizeGLScene ------------------------------------------------------------

GLvoid ReSizeGLScene(int Width, int Height)
{
    glViewport (0, 0, (GLsizei) Width, (GLsizei) Height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    gluPerspective(45.0, (GLfloat) Width / (GLfloat) Height, 0.1, 100.0);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}

// LoadGLTextures ----------------------------------------------------------

GLvoid LoadGLTextures(GLvoid)
{
    LoadTGA(texture, "NeHe.tga");
}

/********************> LoadTGA() <*****/
bool LoadTGA(TextureImage *texture, char *filename)         // Loads A TGA File Into Memory
{    
    GLubyte     TGAheader[12]={0,0,2,0,0,0,0,0,0,0,0,0};    // Uncompressed TGA Header
    GLubyte     TGAcompare[12];                             // Used To Compare TGA Header
    GLubyte     header[6];                                  // First 6 Useful Bytes From The Header
    GLuint      bytesPerPixel;                              // Holds Number Of Bytes Per Pixel Used In The TGA File
    GLuint      imageSize;                                  // Used To Store The Image Size When Setting Aside Ram
    GLuint      temp;                                       // Temporary Variable
    GLuint      type=GL_RGBA;                               // Set The Default GL Mode To RBGA (32 BPP)

    FILE *file = fopen(filename, "rb");                     // Open The TGA File

    if( file==NULL ||                                       // Does File Even Exist?
       fread(TGAcompare,1,sizeof(TGAcompare),file)!=sizeof(TGAcompare) ||   // Are There 12 Bytes To Read?
       memcmp(TGAheader,TGAcompare,sizeof(TGAheader))!=0                ||  // Does The Header Match What We Want?
       fread(header,1,sizeof(header),file)!=sizeof(header))             // If So Read Next 6 Header Bytes
    {
        fclose(file);                                       // If Anything Failed, Close The File
        return false;                                       // Return False
    }

    texture->width  = header[1] * 256 + header[0];          // Determine The TGA Width  (highbyte*256+lowbyte)
    texture->height = header[3] * 256 + header[2];          // Determine The TGA Height (highbyte*256+lowbyte)

    if( texture->width  <=0 ||                              // Is The Width Less Than Or Equal To Zero
       texture->height  <=0 ||                              // Is The Height Less Than Or Equal To Zero
       (header[4]!=24 && header[4]!=32))                    // Is The TGA 24 or 32 Bit?
    {
        fclose(file);                                       // If Anything Failed, Close The File
        return false;                                       // Return False
    }

    texture->bpp    = header[4];                            // Grab The TGA's Bits Per Pixel (24 or 32)
    bytesPerPixel   = texture->bpp/8;                       // Divide By 8 To Get The Bytes Per Pixel
    imageSize       = texture->width*texture->height*bytesPerPixel; // Calculate The Memory Required For The TGA Data

    texture->imageData=(GLubyte *)malloc(imageSize);        // Reserve Memory To Hold The TGA Data

    if( texture->imageData==NULL ||                         // Does The Storage Memory Exist?
       fread(texture->imageData, 1, imageSize, file)!=imageSize)    // Does The Image Size Match The Memory Reserved?
    {
        if(texture->imageData!=NULL)                        // Was Image Data Loaded
            free(texture->imageData);                       // If So, Release The Image Data

        fclose(file);                                       // Close The File
        return false;                                       // Return False
    }

    for(GLuint i=0; i<int(imageSize); i+=bytesPerPixel)     // Loop Through The Image Data
    {                                                       // Swaps The 1st And 3rd Bytes ('R'ed and 'B'lue)
        temp=texture->imageData[i];                         // Temporarily Store The Value At Image Data 'i'
        texture->imageData[i] = texture->imageData[i + 2];  // Set The 1st Byte To The Value Of The 3rd Byte
        texture->imageData[i + 2] = temp;                   // Set The 3rd Byte To The Value In 'temp' (1st Byte Value)
    }

    fclose (file);                                          // Close The File

    // Build A Texture From The Data
    glGenTextures(1, &texture[0].texID);                    // Generate OpenGL texture IDs

    glBindTexture(GL_TEXTURE_2D, texture[0].texID);         // Bind Our Texture
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);   // Linear Filtered
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);   // Linear Filtered

    if (texture[0].bpp==24)                                 // Was The TGA 24 Bits
    {
        type=GL_RGB;                                        // If So Set The 'type' To GL_RGB
    }

    glTexImage2D(GL_TEXTURE_2D, 0, type, texture[0].width, texture[0].height, 0, type, GL_UNSIGNED_BYTE, texture[0].imageData);

    return true;                                            // Texture Building Went Ok, Return True
}

IN LINE 47, and 194 I got

“/Users/mbp/Desktop/XcodeGLUT/main.c:47:0
/Users/mbp/Desktop/XcodeGLUT/main.c:47:
error: expected ‘=’, ‘,’, ‘;’, ‘asm’
or ‘attribute‘ before ‘LoadTGA’

“

I really cannot find anything wrong here..Can anybody help me.

  • 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-05-20T15:03:57+00:00Added an answer on May 20, 2026 at 3:03 pm

    Add #include <stdbool.h> under #include <stdlib.h>

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

Sidebar

Related Questions

I found the following code to create a tinyurl.com url: http://tinyurl.com/api-create.php?url=http://myurl.com This will automatically
I am referring to this code example, which is being reported in https://bugs.java.com/bugdatabase/view_bug?bug_id=6254531 import
Doug McCune had created something that was exactly what I needed ( http://dougmccune.com/blog/2007/05/10/analyze-your-actionscript-code-with-this-apollo-app/ )
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
My create view code like this create VIEW [dbo].[vw_test] AS SELECT 'B' AS rtype,
I want to create maintainable code, but this inheritance situation is causing me problems.
I recently came across this in some code - basically someone trying to create
I'm using PHP5 to create XML files. I have code like this: $doc =
In Delphi, is normal do this: ob = TObject.create; try //code finally ob.free; end;
This code in JS gives me a popup saying i think null is a

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.