<commit_before>// Copyright 2016 <NAME>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Package display TODO doc

package display

import (
	"fmt"
	"runtime"
	"strings"

	"github.com/go-gl/gl/v4.1-core/gl"
	"github.com/go-gl/glfw/v3.1/glfw"
	"github.com/go-gl/mathgl/mgl32"
	"github.com/hurricanerix/shade/events"
)

func init() {
	// GLFW event handling must run on the main OS thread
	runtime.LockOSThread()
}

// Context TODO doc
type Context struct {
	Window     *glfw.Window
	Width      float32
	Height     float32
	Program    uint32
	ProjMatrix mgl32.Mat4
	ViewMatrix mgl32.Mat4
}

// SetMode TODO doc
func SetMode(title string, width, height int) (*Context, error) {
	c := Context{
		Width:  float32(width),
		Height: float32(height),
	}
	if err := glfw.Init(); err != nil {
		return &c, fmt.Errorf("failed to initialize glfw: %v", err)
	}
	// TODO: move this to a terminate function
	//defer glfw.Terminate()

	glfw.WindowHint(glfw.Resizable, glfw.False)
	glfw.WindowHint(glfw.ContextVersionMajor, 4)
	glfw.WindowHint(glfw.ContextVersionMinor, 1)
	glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)
	glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)
	window, err := glfw.CreateWindow(640, 480, title, nil, nil)
	if err != nil {
		return &c, fmt.Errorf("failed to create window: %v", err)
	}
	c.Window = window

	c.Window.MakeContextCurrent()
	c.Window.SetKeyCallback(events.KeyCallback)
	c.Window.SetCursorPosCallback(events.CursorPositionCallback)

	if err := gl.Init(); err != nil {
		return &c, fmt.Errorf("failed to init glow: %v", err)
	}

	fmt.Println("OpenGL version", gl.GoStr(gl.GetString(gl.VERSION)))

	c.Program, err = newProgram(vertexShader, fragmentShader)
	if err != nil {
		return &c, fmt.Errorf("error loading program: %v", err)
	}

	gl.UseProgram(c.Program)

	var left, right, top, bottom, near, far float32
	right = float32(width)<commit_msg>Update OpenGL version to allow older hardware<commit_after>// Copyright 2016 <NAME>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Package display TODO doc

package display

import (
	"fmt"
	"runtime"
	"strings"

	"github.com/go-gl/gl/v4.1-core/gl"
	"github.com/go-gl/glfw/v3.1/glfw"
	"github.com/go-gl/mathgl/mgl32"
	"github.com/hurricanerix/shade/events"
)

func init() {
	// GLFW event handling must run on the main OS thread
	runtime.LockOSThread()
}

// Context TODO doc
type Context struct {
	Window     *glfw.Window
	Width      float32
	Height     float32
	Program    uint32
	ProjMatrix mgl32.Mat4
	ViewMatrix mgl32.Mat4
}

// SetMode TODO doc
func SetMode(title string, width, height int) (*Context, error) {
	c := Context{
		Width:  float32(width),
		Height: float32(height),
	}
	if err := glfw.Init(); err != nil {
		return &c, fmt.Errorf("failed to initialize glfw: %v", err)
	}
	// TODO: move this to a terminate function
	//defer glfw.Terminate()

	glfw.WindowHint(glfw.Resizable, glfw.False)
	glfw.WindowHint(glfw.ContextVersionMajor, 3)
	glfw.WindowHint(glfw.ContextVersionMinor, 3)
	glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)
	glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)
	window, err := glfw.CreateWindow(640, 480, title, nil, nil)
	if err != nil {
		return &c, fmt.Errorf("failed to create window: %v", err)
	}
	c.Window = window

	c.Window.MakeContextCurrent()
	c.Window.SetKeyCallback(events.KeyCallback)
	c.Window.SetCursorPosCallback(events.CursorPositionCallback)

	if err := gl.Init(); err != nil {
		return &c, fmt.Errorf("failed to init glow: %v", err)
	}

	fmt.Println("OpenGL version", gl.GoStr(gl.GetString(gl.VERSION)))

	c.Program, err = newProgram(vertexShader, fragmentShader)
	if err != nil {
		return &c, fmt.Errorf("error loading program: %v", err)
	}

	gl.UseProgram(c.Program)

	var left, right, top, bottom, near, far float32
	right = float32(width)
{'fraction_non_alphanumeric': 0.12339544513457557, 'fraction_numerical': 0.017391304347826087, 'mean_word_length': 3.934627170582227, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1023837', 'n_tokens_mistral': 1692, 'n_tokens_neox': 1610, 'n_words': 485}