<commit_before>// Copyright 2013 <NAME>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Package eng provides functionality for creating 2d games.
package eng

import (
	gl "github.com/chsc/gogl/gl33"
	"github.com/go-gl/glfw"
	"log"
)

// Common OpenGL constants
const (
	BlendZero             = gl.ZERO
	BlendOne              = gl.ONE
	BlendSrcColor         = gl.SRC_COLOR
	BlendOneMinusSrcColor = gl.ONE_MINUS_SRC_COLOR
	BlendDstColor         = gl.DST_COLOR
	BlendOneMinusDstColor = gl.ONE_MINUS_DST_COLOR
	BlendSrcAlpha         = gl.SRC_ALPHA
	BlendOneMinusSrcAlpha = gl.ONE_MINUS_SRC_ALPHA
	BlendDstAlpha         = gl.DST_ALPHA
	BlendOneMinusDstAlpha = gl.ONE_MINUS_DST_ALPHA
	FilterNearest         = gl.NEAREST
	FilterLinear          = gl.LINEAR
	WrapClampToEdge       = gl.CLAMP_TO_EDGE
	WrapRepeat            = gl.REPEAT
	WrapMirroredRepeat    = gl.MIRRORED_REPEAT
)

var (
	responder   Responder
	config      *Config
	timing      *stats
	defaultFont *Font
	bgColor     *Color
)

// A Config holds settings for your game's window and application.
type Config struct {
	// Title is the name of the created window.
	// Default: Untitled
	Title string

	// Width and Height are hints about the size of the window. You
	// may not end up with the indicated size, so you should always
	// query eng for the true width and height after initialization.
	// Default: 1024 x 640
	Width  int
	Height int

	// Fullscreen tells eng whether to open windowed or fullscreen.
	// Default: false
	Fullscreen bool

	// Vsync enables or disables vertical sync which will limit the
	// number of frames rendered per second to your monitor's refresh
	// rate. This may or may not be supported on certain platforms.
	// Default: true
	Vsync bool

	// Resizable tells eng if it should request a window that can be
	// resized by the user of your game.
	// Default: false
	Resizable bool

	// Fsaa indicates how many samples to use for the multisampling
	// buffer. Generally it will be 1, 2, 4, 8, or 16.
	// Default: 1
	Fsaa int

	// PrintFPS turns on a logging of the frames per second to the
	// console every second.
	// Default: false
	LogFPS bool
}

func NewConfig() *Config {
	return &Config{"Untitled", 800, 600, false, true, false, 1, false}
}

// A Responder describes an interface for application events.
//
// Open is called after the opengl context and window have been
// created. You should load assets and create eng objects in this method.
type Responder interface {
	Open()
	Close()
	Update(delta float32)
	Draw()
	MouseMove(x, y int)
	MouseDown(x, y int, button Button)
	MouseUp(x, y int, button Button)
	KeyType(key rune)
	KeyDown(key Key)
	KeyUp(key Key)
	Resize(width, height int)
	MouseScroll(x, y, amount int)
}

func Run(title string, width, height int, fullscreen bool, r Responder) {
	config = &Config{title, width, height, fullscreen, true, false, 1, false}
	RunConfig(config, r)
}

// Run should be called with a type that satisfies the Responder
// interface. Windows will be setup using your Config and a runloop
// will start, blocking the main thread and calling methods on the
// given responder.
func RunConfig(c *Config, r Responder) {
	config = c
	responder = r

	if err := glfw.Init(); err != nil {
		log.Fatal(err)
	}
	defer glfw.Terminate()

	if !config.Resizable {
		glfw.OpenWindowHint(glfw.WindowNoResize, 1)
	}
	glfw.OpenWindowHint(glfw.FsaaSamples, config.Fsaa)

	width := config.Width
	height := config.Height
	mode := glfw.DesktopMode()
	flag := glfw.Windowed

	if config.Fullscreen {
		flag = glfw.Fullscreen
		width = mode.W
		height = mode.H
	}

	if err := glfw.OpenWindow(width, height, 0, 0, 0, 0, 0, 0, flag); err != nil {
		log.Fatal(err)
	}
	defer glfw.CloseWindow()

	config.Width, config.Height = glfw.WindowSize()

	if err := gl.Init(); err != nil {
		log.Fatal(err)
	}

	bgColor = NewColor(0, 0, 0, 0)

	responder.Open()

	if !config.Fullscreen {
		glfw.SetWindowPos((mode.W-width)/2, (mode.H-height)/2)
	}

	if config.Vsync {
		glfw.SetSwapInterval(1)
	}

	glfw.SetWindowTitle(config.Title)

	glfw.SetWindowSizeCallback(func(w, h int) {
		config.Width, config.Height = glfw.WindowSize()
		responder.Resize(w, h)<commit_msg>Ignore glinit errors for now.<commit_after>// Copyright 2013 <NAME>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Package eng provides functionality for creating 2d games.
package eng

import (
	gl "github.com/chsc/gogl/gl33"
	"github.com/go-gl/glfw"
	"log"
)

// Common OpenGL constants
const (
	BlendZero             = gl.ZERO
	BlendOne              = gl.ONE
	BlendSrcColor         = gl.SRC_COLOR
	BlendOneMinusSrcColor = gl.ONE_MINUS_SRC_COLOR
	BlendDstColor         = gl.DST_COLOR
	BlendOneMinusDstColor = gl.ONE_MINUS_DST_COLOR
	BlendSrcAlpha         = gl.SRC_ALPHA
	BlendOneMinusSrcAlpha = gl.ONE_MINUS_SRC_ALPHA
	BlendDstAlpha         = gl.DST_ALPHA
	BlendOneMinusDstAlpha = gl.ONE_MINUS_DST_ALPHA
	FilterNearest         = gl.NEAREST
	FilterLinear          = gl.LINEAR
	WrapClampToEdge       = gl.CLAMP_TO_EDGE
	WrapRepeat            = gl.REPEAT
	WrapMirroredRepeat    = gl.MIRRORED_REPEAT
)

var (
	responder   Responder
	config      *Config
	timing      *stats
	defaultFont *Font
	bgColor     *Color
)

// A Config holds settings for your game's window and application.
type Config struct {
	// Title is the name of the created window.
	// Default: Untitled
	Title string

	// Width and Height are hints about the size of the window. You
	// may not end up with the indicated size, so you should always
	// query eng for the true width and height after initialization.
	// Default: 1024 x 640
	Width  int
	Height int

	// Fullscreen tells eng whether to open windowed or fullscreen.
	// Default: false
	Fullscreen bool

	// Vsync enables or disables vertical sync which will limit the
	// number of frames rendered per second to your monitor's refresh
	// rate. This may or may not be supported on certain platforms.
	// Default: true
	Vsync bool

	// Resizable tells eng if it should request a window that can be
	// resized by the user of your game.
	// Default: false
	Resizable bool

	// Fsaa indicates how many samples to use for the multisampling
	// buffer. Generally it will be 1, 2, 4, 8, or 16.
	// Default: 1
	Fsaa int

	// PrintFPS turns on a logging of the frames per second to the
	// console every second.
	// Default: false
	LogFPS bool
}

func NewConfig() *Config {
	return &Config{"Untitled", 800, 600, false, true, false, 1, false}
}

// A Responder describes an interface for application events.
//
// Open is called after the opengl context and window have been
// created. You should load assets and create eng objects in this method.
type Responder interface {
	Open()
	Close()
	Update(delta float32)
	Draw()
	MouseMove(x, y int)
	MouseDown(x, y int, button Button)
	MouseUp(x, y int, button Button)
	KeyType(key rune)
	KeyDown(key Key)
	KeyUp(key Key)
	Resize(width, height int)
	MouseScroll(x, y, amount int)
}

func Run(title string, width, height int, fullscreen bool, r Responder) {
	config = &Config{title, width, height, fullscreen, true, false, 1, false}
	RunConfig(config, r)
}

// Run should be called with a type that satisfies the Responder
// interface. Windows will be setup using your Config and a runloop
// will start, blocking the main thread and calling methods on the
// given responder.
func RunConfig(c *Config, r Responder) {
	config = c
	responder = r

	if err := glfw.Init(); err != nil {
		log.Fatal(err)
	}
	defer glfw.Terminate()

	if !config.Resizable {
		glfw.OpenWindowHint(glfw.WindowNoResize, 1)
	}
	glfw.OpenWindowHint(glfw.FsaaSamples, config.Fsaa)

	width := config.Width
	height := config.Height
	mode := glfw.DesktopMode()
	flag := glfw.Windowed

	if config.Fullscreen {
		flag = glfw.Fullscreen
		width = mode.W
		height = mode.H
	}

	if err := glfw.OpenWindow(width, height, 0, 0, 0, 0, 0, 0, flag); err != nil {
		log.Fatal(err)
	}
	defer glfw.CloseWindow()

	config.Width, config.Height = glfw.WindowSize()

	if err := gl.Init(); err != nil {
		//		log.Println(err)
	}

	bgColor = NewColor(0, 0, 0, 0)

	responder.Open()

	if !config.Fullscreen {
		glfw.SetWindowPos((mode.W-width)/2, (mode.H-height)/2)
	}

	if config.Vsync {
		glfw.SetSwapInterval(1)
	}

	glfw.SetWindowTitle(config.Title)

	glfw.SetWindowSizeCallback(func(w, h int) {
		config.Width, config.Height = glfw.WindowSize()
		responder.Resize(w, h)
{'fraction_non_alphanumeric': 0.09403615872270486, 'fraction_numerical': 0.010565860530640996, 'mean_word_length': 3.250998003992016, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '383826', 'n_tokens_mistral': 3027, 'n_tokens_neox': 2846, 'n_words': 977}