Skip to content

Instantly share code, notes, and snippets.

@xCyborg
Created June 17, 2023 20:15
Show Gist options
  • Save xCyborg/7e0844e205940000d13377223c1451ab to your computer and use it in GitHub Desktop.
Save xCyborg/7e0844e205940000d13377223c1451ab to your computer and use it in GitHub Desktop.
Simplest OpenGL Xcode Project
/*
* As a first example of using OpenGL in C,
* https://math.hws.edu/graphicsbook/source/glut/first-triangle.c
*/
#include <GLUT/glut.h> // freeglut.h might be a better alternative, if available.....
#include <stdio.h>
#include <stdlib.h>
void display(void) { // Display function will draw the image.
glClearColor( 0, 0, 0, 1 ); // (In fact, this is the default.)
glClear( GL_COLOR_BUFFER_BIT );
glBegin(GL_TRIANGLES);
glColor3f( 1, 0, 0 ); // red
glVertex2f( -1, -1 );
glColor3f( 0, 1, 0 ); // green
glVertex2f( 1, -1 );
glColor3f( 0, 0, 1 ); // blue
glVertex2f( 0, 1 );
glEnd();
glutSwapBuffers(); // Required to copy color buffer onto the screen.
}
int main( int argc, char** argv ) { // Initialize GLUT and
///GL 3D drawing
glutInit(&argc, argv);
// glutInitDisplayMode(GLUT_SINGLE); // Use single color buffer and no depth buffer.
// glutInitWindowSize(500,500); // Size of display area, in pixels.
// glutInitWindowPosition(300,100); // Location of window in screen coordinates.
glutCreateWindow("Hello OpenGL"); // Parameter is window title.
glutDisplayFunc(display); // Called when the window needs to be redrawn.
glutMainLoop(); // Run the event loop! This function does not return.
// Program ends when user closes the window.
return EXIT_SUCCESS;
}
// #include "main.h"
//
// int r = add(23, 9);
// printf("result of sum is: %d\n", r);
//
// draw_cube(10, 5);
// draw_cube(20, 10);
//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment