Initial Commit
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/cmake-build-debug
|
||||
/.idea
|
39
CMakeLists.txt
Normal file
39
CMakeLists.txt
Normal file
@@ -0,0 +1,39 @@
|
||||
cmake_minimum_required(VERSION 3.27)
|
||||
project(JGL
|
||||
VERSION 1.0
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
if (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
|
||||
message(FATAL_ERROR "In-source builds are not allowed")
|
||||
endif()
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
if (WIN32)
|
||||
set(CMAKE_CXX_FLAGS "-municode")
|
||||
endif(WIN32)
|
||||
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
||||
|
||||
|
||||
# Enable Package Managers
|
||||
#include(cmake/CPM.cmake)
|
||||
|
||||
file(GLOB_RECURSE HEADERS "include/*.h" "include/*.hpp")
|
||||
file(GLOB_RECURSE SOURCES "src/*.c" "src/*.cpp" )
|
||||
file(GLOB_RECURSE ASSETS "assets/*")
|
||||
|
||||
add_library(JGL SHARED ${SOURCES}
|
||||
include/JGL/JGL.h
|
||||
src/JGL/JGL.cpp)
|
||||
set_target_properties(JGL PROPERTIES LINKER_LANGUAGE CXX)
|
||||
|
||||
find_package(OpenGL REQUIRED)
|
||||
find_package(GLUT REQUIRED)
|
||||
|
||||
add_executable(JGL_Demo main.cpp)
|
||||
set_target_properties(JGL_Demo PROPERTIES LINK_FLAGS "-Wl,-rpath,./lib")
|
||||
include_directories(${PROJECT_SOURCE_DIR}/include
|
||||
${OPENGL_INCLUDE_DIRS} ${GLUT_INCLUDE_DIRS})
|
||||
|
||||
target_link_libraries(JGL_Demo PUBLIC JGL ${OPENGL_LIBRARIES} ${GLUT_LIBRARIES})
|
26
include/JGL/JGL.h
Normal file
26
include/JGL/JGL.h
Normal file
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// Created by dawsh on 1/17/24.
|
||||
//
|
||||
#pragma once
|
||||
|
||||
// OpenGL Wrapper for rendering 2D graphics primitives in both a 2D and 3D context
|
||||
namespace JGL
|
||||
{
|
||||
void DrawPixel();
|
||||
void DrawLine();
|
||||
void OutlineCircle();
|
||||
void FillCircle();
|
||||
void OutlineTriangle();
|
||||
void FillTriangle();
|
||||
void FillTexturedTriangle();
|
||||
void FillTexturedPolygon();
|
||||
void DrawSprite();
|
||||
void DrawPartialSprite();
|
||||
void DrawString();
|
||||
void FillRect();
|
||||
void OutlineRect();
|
||||
void OutlinePolygon();
|
||||
void FillPolygon();
|
||||
|
||||
void GradientFillRect();
|
||||
}
|
129
main.cpp
Normal file
129
main.cpp
Normal file
@@ -0,0 +1,129 @@
|
||||
#include <GL/glut.h>
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
void initGL()
|
||||
{
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
|
||||
void display() {
|
||||
glClear(GL_COLOR_BUFFER_BIT); // Clear the color buffer
|
||||
glMatrixMode(GL_MODELVIEW); // To operate on the Model-View matrix
|
||||
glLoadIdentity(); // Reset the model-view matrix.
|
||||
|
||||
|
||||
// Define shapes enclosed within a pair of glBegin and glEnd
|
||||
|
||||
glBegin(GL_QUADS); // Each set of 4 vertices form a quad
|
||||
glColor3f(1.f, 0.f, 0.f);
|
||||
glVertex2f(-0.8f, 0.1f);
|
||||
glVertex2f(-0.2f, 0.1f);
|
||||
glVertex2f(-0.2f, 0.7f);
|
||||
glVertex2f(-0.8f, 0.7f);
|
||||
|
||||
glColor3f(0.0f, 1.0f, 0.0f); // Green
|
||||
glVertex2f(-0.7f, -0.6f);
|
||||
glVertex2f(-0.1f, -0.6f);
|
||||
glVertex2f(-0.1f, 0.0f);
|
||||
glVertex2f(-0.7f, 0.0f);
|
||||
|
||||
glColor3f(0.2f, 0.2f, 0.2f); // Dark Gray
|
||||
glVertex2f(-0.9f, -0.7f);
|
||||
glColor3f(1.f, 1.f, 1.f); // White
|
||||
glVertex2f(-0.5f, -0.7f);
|
||||
glColor3f(.2f, .2f, .2f); // Dark Gray
|
||||
glVertex2f(-0.5f, -0.3f);
|
||||
glColor3f(1.f, 1.f, 1.f); // White
|
||||
glVertex2f(-0.9f, -0.3f);
|
||||
glEnd();
|
||||
|
||||
glBegin(GL_TRIANGLES);
|
||||
glColor3f(0.0f, 0.0f, 1.f); // Blue
|
||||
glVertex2f(0.1f, -0.6f);
|
||||
glVertex2f(0.7f, -0.6f);
|
||||
glVertex2f(0.4f, -0.1f);
|
||||
|
||||
glColor3f(1.f, 0.f, 0.f); // Red
|
||||
glVertex2f(0.3f, -0.4f);
|
||||
glColor3f(0.0f, 1.0f, 0.f); // Green
|
||||
glVertex2f(0.9f, -0.4f);
|
||||
glColor3f(0.f, 0.f, 1.f); // Blue
|
||||
glVertex2f(0.6f, -0.9f);
|
||||
glEnd();
|
||||
|
||||
glBegin(GL_POLYGON); // These verts form a closed polygon
|
||||
glColor3f(1.f, 1.f, 0.f); // Yellow
|
||||
glVertex2f(0.4f, 0.2f);
|
||||
glVertex2f(0.6f, 0.2f);
|
||||
glVertex2f(0.7f, 0.4f);
|
||||
glVertex2f(0.6f, 0.6f);
|
||||
glVertex2f(0.4f, 0.6f);
|
||||
glVertex2f(0.3f, 0.4f);
|
||||
glEnd();
|
||||
|
||||
glFlush(); // Render now
|
||||
}
|
||||
|
||||
int windowWidth = 640; // Windowed mode's width
|
||||
int windowHeight = 480; // Windowed mode's height
|
||||
int windowPosX = 50; // Windowed mode's top-left corner x
|
||||
int windowPosY = 50; // Windowed mode's top-left corner y
|
||||
bool fullscreenMode = true;
|
||||
|
||||
void specialKeys(int key, int x, int y) {
|
||||
switch(key) {
|
||||
case GLUT_KEY_F1:
|
||||
fullscreenMode = !fullscreenMode;
|
||||
if (fullscreenMode) {
|
||||
windowPosX = glutGet(GLUT_WINDOW_X);
|
||||
windowPosY = glutGet(GLUT_WINDOW_Y);
|
||||
windowWidth = glutGet(GLUT_WINDOW_WIDTH);
|
||||
windowHeight = glutGet(GLUT_WINDOW_HEIGHT);
|
||||
|
||||
glutFullScreen();
|
||||
} else {
|
||||
glutReshapeWindow(windowWidth, windowHeight);
|
||||
glutPositionWindow(windowPosX, windowPosY);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Handler for window re-size event. Called back when the window first appears
|
||||
// and whenever the window is re-sized with its new width and height
|
||||
void reshape(GLsizei width, GLsizei height) {
|
||||
if (height == 0) height = 1;
|
||||
GLfloat aspect = (GLfloat) width / (GLfloat) height;
|
||||
|
||||
// Set the viewport to cover the new window
|
||||
glViewport(0, 0, width, height);
|
||||
|
||||
// Set the aspect ratio of the clipping area to match the viewport
|
||||
glMatrixMode(GL_PROJECTION); // Operate on the Projection Matrix;
|
||||
glLoadIdentity(); // Reset the projection matrix
|
||||
if (width >= height) {
|
||||
// Aspect >= 1, set the height from -1 to 1
|
||||
gluOrtho2D(-1.0 * aspect, 1.0 * aspect, -1.0, 1.0);
|
||||
} else {
|
||||
// Aspect < 1, set the width from -1 to 1, with larger height
|
||||
gluOrtho2D(-1.0, 1.0, -1.0 / aspect, 1.0 / aspect);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
glutInit(&argc, argv); // Initialize GLUT
|
||||
glutCreateWindow("Vertex, Primitive, & Color"); // Create window with given title
|
||||
glutInitWindowSize(320, 320); // Set the window's initial width & height - non-square
|
||||
glutInitWindowPosition(50, 50); // Position the window's initial top-left corner
|
||||
glutDisplayFunc(display); // Register callback handler for window re-paint event
|
||||
glutReshapeFunc(reshape); // Register callback handler for window re-size event
|
||||
glutSpecialFunc(specialKeys); // Register callback handler for special-key event
|
||||
initGL(); // Our own OpenGL initialization
|
||||
glutMainLoop();
|
||||
return 0;
|
||||
}
|
3
src/JGL/JGL.cpp
Normal file
3
src/JGL/JGL.cpp
Normal file
@@ -0,0 +1,3 @@
|
||||
//
|
||||
// Created by dawsh on 1/17/24.
|
||||
//
|
Reference in New Issue
Block a user