Skip to content

Instantly share code, notes, and snippets.

@n00bmind
Created December 24, 2022 16:33
Show Gist options
  • Save n00bmind/77ad638f4b13a3c1466aeb13e5f3905a to your computer and use it in GitHub Desktop.
Save n00bmind/77ad638f4b13a3c1466aeb13e5f3905a to your computer and use it in GitHub Desktop.
Jai OpenGL setup
#import "Basic";
#scope_file
#import "String";
#import "System";
#import "Window_Creation";
#import "Input";
#import "Windows";
#import "GL"; //( DUMP_GL_ERRORS = true );
Simp :: #import "Simp";
#load "opengl.jai";
// TODO Add to autosaved state & configuration
WINDOW_WIDTH :: 900;
//WINDOW_HEIGHT :: 720;
mainWindow: Window_Type;
NvOptimusEnablement : DWORD = 0x01;
AmdPowerXpressRequestHighPerformance : DWORD = 0x01;
#scope_export
main :: ()
{
path := path_strip_filename( get_path_of_running_executable() );
set_working_directory( join( path, "/.." ) );
path = get_working_directory();
print( "Working directory is '%'\n", path );
// TODO Do this in a cross-platform way
screenWidth := GetSystemMetrics( SM_CXSCREEN );
screenHeight := GetSystemMetrics( SM_CYSCREEN );
// TODO May want to get more platform specific at some point for events etc? idk
mainWindow = create_window( WINDOW_WIDTH, screenHeight, "r.e.p.l.r.", (screenWidth - WINDOW_WIDTH) / 2, 0 );
if( !mainWindow )
exit( 1 );
if( !OpenGLInit( mainWindow ) )
exit( 1 );
pixelHeight := screenHeight / 24;
mainFont := Simp.get_font_at_size("data/fonts", "consolas_nf_regular.ttf", pixelHeight );
if( mainFont == null )
{
print( "Failed loading font 'data/fonts/consolas_nf_regular.ttf'\n" );
exit( 1 );
}
quit := false;
while !quit
{
update_window_events();
for events_this_frame
{
if it.type == .QUIT
quit = true;
else if it.type == .KEYBOARD
{
if it.key_pressed == 0
continue;
//if it.key_code == .ESCAPE
//quit = true;
}
}
OpenGLDrawTest( WINDOW_WIDTH, screenHeight );
}
exit( 0 );
}
OpenGLInit :: ( window: Window_Type ) -> bool
{
// TODO Error handling!?
gl_create_context( window, 3, 3,
compatibility = false, debug = true );
gl_load( *gl );
gl_enable_debug_output( break_on_error = true );
// TODO Shaders etc
DumpGLErrors( "context" );
return true;
}
OpenGLDrawTest :: ( viewportWidth: int, viewportHeight: int )
{
//glViewport( 0, 0, xx viewportWidth, xx viewportHeight );
glViewport( 0, 0, 100, 100 );
//glDisable( GL_SCISSOR_TEST );
//glEnable( GL_CULL_FACE );
//glEnable( GL_DEPTH_TEST );
//glFrontFace( GL_CCW );
//// TODO Create a 1x1 white texture to bind here so that shaders that use samplers
//// don't have to check whether there's a 'valid' texture or not
//glBindTexture( GL_TEXTURE_2D, 0 );
glClearColor( 1.0, 0.0, 0.0, 0.0 );
glClear( GL_COLOR_BUFFER_BIT );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment