Update C sources and examples
58
examples/core/vr_simulator/main.go
Normal file
|
@ -0,0 +1,58 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
screenWidth := int32(1080)
|
||||
screenHeight := int32(600)
|
||||
|
||||
// NOTE: screenWidth/screenHeight should match VR device aspect ratio
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [core] example - vr simulator")
|
||||
|
||||
// NOTE: default device (simulator)
|
||||
raylib.InitVrSimulator(raylib.HmdOculusRiftCv1) // Init VR device (Oculus Rift CV1)
|
||||
|
||||
camera := raylib.Camera{}
|
||||
camera.Position = raylib.NewVector3(5.0, 2.0, 5.0) // Camera position
|
||||
camera.Target = raylib.NewVector3(0.0, 2.0, 0.0) // Camera looking at point
|
||||
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0) // Camera up vector (rotation towards target)
|
||||
camera.Fovy = 60.0 // Camera field-of-view Y
|
||||
|
||||
cubePosition := raylib.NewVector3(0.0, 0.0, 0.0)
|
||||
|
||||
raylib.SetCameraMode(camera, raylib.CameraFirstPerson) // Set first person camera mode
|
||||
|
||||
raylib.SetTargetFPS(90)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
raylib.UpdateCamera(&camera) // Update camera (simulator mode)
|
||||
|
||||
raylib.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
|
||||
raylib.BeginVrDrawing()
|
||||
|
||||
raylib.Begin3dMode(camera)
|
||||
|
||||
raylib.DrawCube(cubePosition, 2.0, 2.0, 2.0, raylib.Red)
|
||||
raylib.DrawCubeWires(cubePosition, 2.0, 2.0, 2.0, raylib.Maroon)
|
||||
|
||||
raylib.DrawGrid(40, 1.0)
|
||||
|
||||
raylib.End3dMode()
|
||||
|
||||
raylib.EndVrDrawing()
|
||||
|
||||
raylib.DrawFPS(10, 10)
|
||||
|
||||
raylib.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.CloseVrSimulator() // Close VR simulator
|
||||
|
||||
raylib.CloseWindow()
|
||||
}
|
BIN
examples/shaders/shapes_textures/fudesumi.png
Normal file
After Width: | Height: | Size: 218 KiB |
|
@ -10,7 +10,7 @@ func main() {
|
|||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [shaders] example - shapes and texture shaders")
|
||||
|
||||
sonic := raylib.LoadTexture("sonic.png")
|
||||
fudesumi := raylib.LoadTexture("fudesumi.png")
|
||||
|
||||
// NOTE: Using GLSL 330 shader version, on OpenGL ES 2.0 use GLSL 100 shader version
|
||||
shader := raylib.LoadShader("glsl330/base.vs", "glsl330/grayscale.fs")
|
||||
|
@ -57,16 +57,18 @@ func main() {
|
|||
// Activate our custom shader to be applied on next shapes/textures drawings
|
||||
raylib.BeginShaderMode(shader)
|
||||
|
||||
raylib.DrawTexture(sonic, 380, -10, raylib.White) // Using custom shader
|
||||
raylib.DrawTexture(fudesumi, 500, -30, raylib.White) // Using custom shader
|
||||
|
||||
// Activate our default shader for next drawings
|
||||
raylib.EndShaderMode()
|
||||
|
||||
raylib.DrawText("(c) Fudesumi sprite by Eiden Marsal", 380, screenHeight-20, 10, raylib.Gray)
|
||||
|
||||
raylib.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadShader(shader) // Unload shader
|
||||
raylib.UnloadTexture(sonic) // Unload texture
|
||||
raylib.UnloadShader(shader) // Unload shader
|
||||
raylib.UnloadTexture(fudesumi) // Unload texture
|
||||
|
||||
raylib.CloseWindow() // Close window and OpenGL context
|
||||
}
|
||||
|
|
Before Width: | Height: | Size: 114 KiB |
36
examples/shapes/lines_bezier/main.go
Normal file
|
@ -0,0 +1,36 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [shapes] example - cubic-bezier lines")
|
||||
|
||||
start := raylib.NewVector2(0, 0)
|
||||
end := raylib.NewVector2(float32(screenWidth), float32(screenHeight))
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
if raylib.IsMouseButtonDown(raylib.MouseLeftButton) {
|
||||
start = raylib.GetMousePosition()
|
||||
} else if raylib.IsMouseButtonDown(raylib.MouseRightButton) {
|
||||
end = raylib.GetMousePosition()
|
||||
}
|
||||
|
||||
raylib.BeginDrawing()
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
|
||||
raylib.DrawText("USE MOUSE LEFT-RIGHT CLICK to DEFINE LINE START and END POINTS", 15, 20, 20, raylib.Gray)
|
||||
|
||||
raylib.DrawLineBezier(start, end, 2.0, raylib.Red)
|
||||
|
||||
raylib.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.CloseWindow()
|
||||
}
|
|
@ -1,140 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [text] example - font selector")
|
||||
|
||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||
fonts := make([]raylib.SpriteFont, 8) // SpriteFont array
|
||||
|
||||
fonts[0] = raylib.LoadSpriteFont("fonts/alagard.rbmf") // SpriteFont loading
|
||||
fonts[1] = raylib.LoadSpriteFont("fonts/pixelplay.rbmf") // SpriteFont loading
|
||||
fonts[2] = raylib.LoadSpriteFont("fonts/mecha.rbmf") // SpriteFont loading
|
||||
fonts[3] = raylib.LoadSpriteFont("fonts/setback.rbmf") // SpriteFont loading
|
||||
fonts[4] = raylib.LoadSpriteFont("fonts/romulus.rbmf") // SpriteFont loading
|
||||
fonts[5] = raylib.LoadSpriteFont("fonts/pixantiqua.rbmf") // SpriteFont loading
|
||||
fonts[6] = raylib.LoadSpriteFont("fonts/alpha_beta.rbmf") // SpriteFont loading
|
||||
fonts[7] = raylib.LoadSpriteFont("fonts/jupiter_crash.rbmf") // SpriteFont loading
|
||||
|
||||
currentFont := 0 // Selected font
|
||||
|
||||
colors := [8]raylib.Color{raylib.Maroon, raylib.Orange, raylib.DarkGreen, raylib.DarkBlue, raylib.DarkPurple, raylib.Lime, raylib.Gold, raylib.Red}
|
||||
|
||||
fontNames := [8]string{"[0] Alagard", "[1] PixelPlay", "[2] MECHA", "[3] Setback", "[4] Romulus", "[5] PixAntiqua", "[6] Alpha Beta", "[7] Jupiter Crash"}
|
||||
|
||||
text := "THIS is THE FONT you SELECTED!" // Main text
|
||||
|
||||
textSize := raylib.MeasureTextEx(fonts[currentFont], text, float32(fonts[currentFont].BaseSize)*3, 1)
|
||||
|
||||
mousePoint := raylib.Vector2{}
|
||||
|
||||
btnNextOutColor := raylib.DarkBlue // Button color (outside line)
|
||||
btnNextInColor := raylib.SkyBlue // Button color (inside)
|
||||
|
||||
framesCounter := 0 // Useful to count frames button is 'active' = clicked
|
||||
|
||||
positionY := int32(180) // Text selector and button Y position
|
||||
|
||||
btnNextRec := raylib.NewRectangle(673, positionY, 109, 44) // Button rectangle (useful for collision)
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
// Update
|
||||
|
||||
// Keyboard-based font selection (easy)
|
||||
if raylib.IsKeyPressed(raylib.KeyRight) {
|
||||
if currentFont < 7 {
|
||||
currentFont++
|
||||
}
|
||||
}
|
||||
|
||||
if raylib.IsKeyPressed(raylib.KeyLeft) {
|
||||
if currentFont > 0 {
|
||||
currentFont--
|
||||
}
|
||||
}
|
||||
|
||||
if raylib.IsKeyPressed('0') {
|
||||
currentFont = 0
|
||||
} else if raylib.IsKeyPressed('1') {
|
||||
currentFont = 1
|
||||
} else if raylib.IsKeyPressed('2') {
|
||||
currentFont = 2
|
||||
} else if raylib.IsKeyPressed('3') {
|
||||
currentFont = 3
|
||||
} else if raylib.IsKeyPressed('4') {
|
||||
currentFont = 4
|
||||
} else if raylib.IsKeyPressed('5') {
|
||||
currentFont = 5
|
||||
} else if raylib.IsKeyPressed('6') {
|
||||
currentFont = 6
|
||||
} else if raylib.IsKeyPressed('7') {
|
||||
currentFont = 7
|
||||
}
|
||||
|
||||
// Mouse-based font selection (NEXT button logic)
|
||||
mousePoint = raylib.GetMousePosition()
|
||||
|
||||
if raylib.CheckCollisionPointRec(mousePoint, btnNextRec) {
|
||||
// Mouse hover button logic
|
||||
if framesCounter == 0 {
|
||||
btnNextOutColor = raylib.DarkPurple
|
||||
btnNextInColor = raylib.Purple
|
||||
}
|
||||
|
||||
if raylib.IsMouseButtonDown(raylib.MouseLeftButton) {
|
||||
framesCounter = 20 // Frames button is 'active'
|
||||
btnNextOutColor = raylib.Maroon
|
||||
btnNextInColor = raylib.Red
|
||||
}
|
||||
} else {
|
||||
// Mouse not hover button
|
||||
btnNextOutColor = raylib.DarkBlue
|
||||
btnNextInColor = raylib.SkyBlue
|
||||
}
|
||||
|
||||
if framesCounter > 0 {
|
||||
framesCounter--
|
||||
}
|
||||
|
||||
if framesCounter == 1 { // We change font on frame 1
|
||||
currentFont++
|
||||
if currentFont > 7 {
|
||||
currentFont = 0
|
||||
}
|
||||
}
|
||||
|
||||
// Text measurement for better positioning on screen
|
||||
textSize = raylib.MeasureTextEx(fonts[currentFont], text, float32(fonts[currentFont].BaseSize)*3, 1)
|
||||
|
||||
// Draw
|
||||
raylib.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
|
||||
raylib.DrawText("font selector - use arroys, button or numbers", 160, 80, 20, raylib.DarkGray)
|
||||
raylib.DrawLine(120, 120, 680, 120, raylib.DarkGray)
|
||||
|
||||
raylib.DrawRectangle(18, positionY, 644, 44, raylib.DarkGray)
|
||||
raylib.DrawRectangle(20, positionY+2, 640, 40, raylib.LightGray)
|
||||
raylib.DrawText(fontNames[currentFont], 30, positionY+13, 20, raylib.Black)
|
||||
raylib.DrawText("< >", 610, positionY+8, 30, raylib.Black)
|
||||
|
||||
raylib.DrawRectangleRec(btnNextRec, btnNextOutColor)
|
||||
raylib.DrawRectangle(675, positionY+2, 105, 40, btnNextInColor)
|
||||
raylib.DrawText("NEXT", 700, positionY+13, 20, btnNextOutColor)
|
||||
|
||||
raylib.DrawTextEx(fonts[currentFont], text, raylib.NewVector2(float32(screenWidth)/2-textSize.X/2, 260+(70-textSize.Y)/2), float32(fonts[currentFont].BaseSize*3), 1, colors[currentFont])
|
||||
|
||||
raylib.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.CloseWindow()
|
||||
}
|
BIN
examples/text/raylib_fonts/fonts/alagard.png
Normal file
After Width: | Height: | Size: 4.3 KiB |
BIN
examples/text/raylib_fonts/fonts/alpha_beta.png
Normal file
After Width: | Height: | Size: 2.4 KiB |
BIN
examples/text/raylib_fonts/fonts/jupiter_crash.png
Normal file
After Width: | Height: | Size: 3.4 KiB |
BIN
examples/text/raylib_fonts/fonts/mecha.png
Normal file
After Width: | Height: | Size: 2.3 KiB |
BIN
examples/text/raylib_fonts/fonts/pixantiqua.png
Normal file
After Width: | Height: | Size: 2.9 KiB |
BIN
examples/text/raylib_fonts/fonts/pixelplay.png
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
examples/text/raylib_fonts/fonts/romulus.png
Normal file
After Width: | Height: | Size: 2.9 KiB |
BIN
examples/text/raylib_fonts/fonts/setback.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
|
@ -4,21 +4,23 @@ import (
|
|||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const maxFonts = 8
|
||||
|
||||
func main() {
|
||||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [text] example - rBMF fonts")
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [text] example - raylib fonts")
|
||||
|
||||
fonts := make([]raylib.SpriteFont, 8)
|
||||
fonts[0] = raylib.LoadSpriteFont("fonts/alagard.rbmf")
|
||||
fonts[1] = raylib.LoadSpriteFont("fonts/pixelplay.rbmf")
|
||||
fonts[2] = raylib.LoadSpriteFont("fonts/mecha.rbmf")
|
||||
fonts[3] = raylib.LoadSpriteFont("fonts/setback.rbmf")
|
||||
fonts[4] = raylib.LoadSpriteFont("fonts/romulus.rbmf")
|
||||
fonts[5] = raylib.LoadSpriteFont("fonts/pixantiqua.rbmf")
|
||||
fonts[6] = raylib.LoadSpriteFont("fonts/alpha_beta.rbmf")
|
||||
fonts[7] = raylib.LoadSpriteFont("fonts/jupiter_crash.rbmf")
|
||||
fonts := make([]raylib.SpriteFont, maxFonts)
|
||||
fonts[0] = raylib.LoadSpriteFont("fonts/alagard.png")
|
||||
fonts[1] = raylib.LoadSpriteFont("fonts/pixelplay.png")
|
||||
fonts[2] = raylib.LoadSpriteFont("fonts/mecha.png")
|
||||
fonts[3] = raylib.LoadSpriteFont("fonts/setback.png")
|
||||
fonts[4] = raylib.LoadSpriteFont("fonts/romulus.png")
|
||||
fonts[5] = raylib.LoadSpriteFont("fonts/pixantiqua.png")
|
||||
fonts[6] = raylib.LoadSpriteFont("fonts/alpha_beta.png")
|
||||
fonts[7] = raylib.LoadSpriteFont("fonts/jupiter_crash.png")
|
||||
|
||||
messages := []string{
|
||||
"ALAGARD FONT designed by Hewett Tsoi",
|
||||
|
@ -32,15 +34,20 @@ func main() {
|
|||
}
|
||||
|
||||
spacings := []int32{2, 4, 8, 4, 3, 4, 4, 1}
|
||||
positions := make([]raylib.Vector2, 8)
|
||||
positions := make([]raylib.Vector2, maxFonts)
|
||||
|
||||
var i int32
|
||||
for i = 0; i < 8; i++ {
|
||||
for i = 0; i < maxFonts; i++ {
|
||||
x := screenWidth/2 - int32(raylib.MeasureTextEx(fonts[i], messages[i], float32(fonts[i].BaseSize*2), spacings[i]).X/2)
|
||||
y := 60 + fonts[i].BaseSize + 45*i
|
||||
positions[i] = raylib.NewVector2(float32(x), float32(y))
|
||||
}
|
||||
|
||||
// Small Y position corrections
|
||||
positions[3].Y += 8
|
||||
positions[4].Y += 2
|
||||
positions[7].Y -= 8
|
||||
|
||||
colors := []raylib.Color{raylib.Maroon, raylib.Orange, raylib.DarkGreen, raylib.DarkBlue, raylib.DarkPurple, raylib.Lime, raylib.Gold, raylib.DarkBrown}
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
|
@ -52,14 +59,14 @@ func main() {
|
|||
raylib.DrawText("free fonts included with raylib", 250, 20, 20, raylib.DarkGray)
|
||||
raylib.DrawLine(220, 50, 590, 50, raylib.DarkGray)
|
||||
|
||||
for i = 0; i < 8; i++ {
|
||||
for i = 0; i < maxFonts; i++ {
|
||||
raylib.DrawTextEx(fonts[i], messages[i], positions[i], float32(fonts[i].BaseSize*2), spacings[i], colors[i])
|
||||
}
|
||||
|
||||
raylib.EndDrawing()
|
||||
}
|
||||
|
||||
for i = 0; i < 8; i++ {
|
||||
for i = 0; i < maxFonts; i++ {
|
||||
raylib.UnloadSpriteFont(fonts[i])
|
||||
}
|
||||
|
|
@ -19,7 +19,7 @@ func main() {
|
|||
fontChars := int32(0)
|
||||
|
||||
// TTF SpriteFont loading with custom generation parameters
|
||||
font := raylib.LoadSpriteFontTTF("fonts/KAISG.ttf", 96, 0, &fontChars)
|
||||
font := raylib.LoadSpriteFontEx("fonts/KAISG.ttf", 96, 0, &fontChars)
|
||||
|
||||
// Generate mipmap levels to use trilinear filtering
|
||||
// NOTE: On 2D drawing it won't be noticeable, it looks like FILTER_BILINEAR
|
||||
|
@ -69,7 +69,7 @@ func main() {
|
|||
|
||||
if count == 1 { // Only support one ttf file dropped
|
||||
raylib.UnloadSpriteFont(font)
|
||||
font = raylib.LoadSpriteFontTTF(droppedFiles[0], fontSize, 0, &fontChars)
|
||||
font = raylib.LoadSpriteFontEx(droppedFiles[0], fontSize, 0, &fontChars)
|
||||
raylib.ClearDroppedFiles()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,220 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const numTextures = 24
|
||||
|
||||
// Formats
|
||||
const (
|
||||
PngR8g8b8a8 = iota
|
||||
PvrGrayscale
|
||||
PvrGrayAlpha
|
||||
PvrR5g6b5
|
||||
PvrR5g5b5a1
|
||||
PvrR4g4b4a4
|
||||
DdsR5g6b5
|
||||
DdsR5g5b5a1
|
||||
DdsR4g4b4a4
|
||||
DdsR8g8b8a8
|
||||
DdsDxt1Rgb
|
||||
DdsDxt1Rgba
|
||||
DdsDxt3Rgba
|
||||
DdsDxt5Rgba
|
||||
PkmEtc1Rgb
|
||||
PkmEtc2Rgb
|
||||
PkmEtc2EacRgba
|
||||
KtxEtc1Rgb
|
||||
KtxEtc2Rgb
|
||||
KtxEtc2EacRgba
|
||||
Astc4x4Ldr
|
||||
Astc8x8Ldr
|
||||
PvrPvrtRgb
|
||||
PvrPvrtRgba
|
||||
)
|
||||
|
||||
var formatText = []string{
|
||||
"PNG_R8G8B8A8",
|
||||
"PVR_GRAYSCALE",
|
||||
"PVR_GRAY_ALPHA",
|
||||
"PVR_R5G6B5",
|
||||
"PVR_R5G5B5A1",
|
||||
"PVR_R4G4B4A4",
|
||||
"DDS_R5G6B5",
|
||||
"DDS_R5G5B5A1",
|
||||
"DDS_R4G4B4A4",
|
||||
"DDS_R8G8B8A8",
|
||||
"DDS_DXT1_RGB",
|
||||
"DDS_DXT1_RGBA",
|
||||
"DDS_DXT3_RGBA",
|
||||
"DDS_DXT5_RGBA",
|
||||
"PKM_ETC1_RGB",
|
||||
"PKM_ETC2_RGB",
|
||||
"PKM_ETC2_EAC_RGBA",
|
||||
"KTX_ETC1_RGB",
|
||||
"KTX_ETC2_RGB",
|
||||
"KTX_ETC2_EAC_RGBA",
|
||||
"ASTC_4x4_LDR",
|
||||
"ASTC_8x8_LDR",
|
||||
"PVR_PVRT_RGB",
|
||||
"PVR_PVRT_RGBA",
|
||||
}
|
||||
|
||||
func main() {
|
||||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture formats loading")
|
||||
|
||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||
|
||||
sonic := make([]raylib.Texture2D, numTextures)
|
||||
|
||||
sonic[PngR8g8b8a8] = raylib.LoadTexture("texture_formats/sonic.png")
|
||||
|
||||
// Load UNCOMPRESSED PVR texture data
|
||||
sonic[PvrGrayscale] = raylib.LoadTexture("texture_formats/sonic_GRAYSCALE.pvr")
|
||||
sonic[PvrGrayAlpha] = raylib.LoadTexture("texture_formats/sonic_L8A8.pvr")
|
||||
sonic[PvrR5g6b5] = raylib.LoadTexture("texture_formats/sonic_R5G6B5.pvr")
|
||||
sonic[PvrR5g5b5a1] = raylib.LoadTexture("texture_formats/sonic_R5G5B5A1.pvr")
|
||||
sonic[PvrR4g4b4a4] = raylib.LoadTexture("texture_formats/sonic_R4G4B4A4.pvr")
|
||||
|
||||
// Load UNCOMPRESSED DDS texture data
|
||||
sonic[DdsR5g6b5] = raylib.LoadTexture("texture_formats/sonic_R5G6B5.dds")
|
||||
sonic[DdsR5g5b5a1] = raylib.LoadTexture("texture_formats/sonic_A1R5G5B5.dds")
|
||||
sonic[DdsR4g4b4a4] = raylib.LoadTexture("texture_formats/sonic_A4R4G4B4.dds")
|
||||
sonic[DdsR8g8b8a8] = raylib.LoadTexture("texture_formats/sonic_A8R8G8B8.dds")
|
||||
|
||||
// Load COMPRESSED DXT DDS texture data (if supported)
|
||||
sonic[DdsDxt1Rgb] = raylib.LoadTexture("texture_formats/sonic_DXT1_RGB.dds")
|
||||
sonic[DdsDxt1Rgba] = raylib.LoadTexture("texture_formats/sonic_DXT1_RGBA.dds")
|
||||
sonic[DdsDxt3Rgba] = raylib.LoadTexture("texture_formats/sonic_DXT3_RGBA.dds")
|
||||
sonic[DdsDxt5Rgba] = raylib.LoadTexture("texture_formats/sonic_DXT5_RGBA.dds")
|
||||
|
||||
// Load COMPRESSED ETC texture data (if supported)
|
||||
sonic[PkmEtc1Rgb] = raylib.LoadTexture("texture_formats/sonic_ETC1_RGB.pkm")
|
||||
sonic[PkmEtc2Rgb] = raylib.LoadTexture("texture_formats/sonic_ETC2_RGB.pkm")
|
||||
sonic[PkmEtc2EacRgba] = raylib.LoadTexture("texture_formats/sonic_ETC2_EAC_RGBA.pkm")
|
||||
|
||||
sonic[KtxEtc1Rgb] = raylib.LoadTexture("texture_formats/sonic_ETC1_RGB.ktx")
|
||||
sonic[KtxEtc2Rgb] = raylib.LoadTexture("texture_formats/sonic_ETC2_RGB.ktx")
|
||||
sonic[KtxEtc2EacRgba] = raylib.LoadTexture("texture_formats/sonic_ETC2_EAC_RGBA.ktx")
|
||||
|
||||
// Load COMPRESSED ASTC texture data (if supported)
|
||||
sonic[Astc4x4Ldr] = raylib.LoadTexture("texture_formats/sonic_ASTC_4x4_ldr.astc")
|
||||
sonic[Astc8x8Ldr] = raylib.LoadTexture("texture_formats/sonic_ASTC_8x8_ldr.astc")
|
||||
|
||||
// Load COMPRESSED PVR texture data (if supported)
|
||||
sonic[PvrPvrtRgb] = raylib.LoadTexture("texture_formats/sonic_PVRT_RGB.pvr")
|
||||
sonic[PvrPvrtRgba] = raylib.LoadTexture("texture_formats/sonic_PVRT_RGBA.pvr")
|
||||
|
||||
selectedFormat := PngR8g8b8a8
|
||||
|
||||
selectRecs := make([]raylib.Rectangle, numTextures)
|
||||
|
||||
for i := 0; i < numTextures; i++ {
|
||||
if i < numTextures/2 {
|
||||
selectRecs[i] = raylib.NewRectangle(40, int32(30+32*i), 150, 30)
|
||||
} else {
|
||||
selectRecs[i] = raylib.NewRectangle(40+152, int32(30+32*(i-numTextures/2)), 150, 30)
|
||||
}
|
||||
}
|
||||
|
||||
// Texture sizes in KB
|
||||
var textureSizes = [numTextures]int{
|
||||
512 * 512 * 32 / 8 / 1024, //PNG_R8G8B8A8 (32 bpp)
|
||||
512 * 512 * 8 / 8 / 1024, //PVR_GRAYSCALE (8 bpp)
|
||||
512 * 512 * 16 / 8 / 1024, //PVR_GRAY_ALPHA (16 bpp)
|
||||
512 * 512 * 16 / 8 / 1024, //PVR_R5G6B5 (16 bpp)
|
||||
512 * 512 * 16 / 8 / 1024, //PVR_R5G5B5A1 (16 bpp)
|
||||
512 * 512 * 16 / 8 / 1024, //PVR_R4G4B4A4 (16 bpp)
|
||||
512 * 512 * 16 / 8 / 1024, //DDS_R5G6B5 (16 bpp)
|
||||
512 * 512 * 16 / 8 / 1024, //DDS_R5G5B5A1 (16 bpp)
|
||||
512 * 512 * 16 / 8 / 1024, //DDS_R4G4B4A4 (16 bpp)
|
||||
512 * 512 * 32 / 8 / 1024, //DDS_R8G8B8A8 (32 bpp)
|
||||
512 * 512 * 4 / 8 / 1024, //DDS_DXT1_RGB (4 bpp) -Compressed-
|
||||
512 * 512 * 4 / 8 / 1024, //DDS_DXT1_RGBA (4 bpp) -Compressed-
|
||||
512 * 512 * 8 / 8 / 1024, //DDS_DXT3_RGBA (8 bpp) -Compressed-
|
||||
512 * 512 * 8 / 8 / 1024, //DDS_DXT5_RGBA (8 bpp) -Compressed-
|
||||
512 * 512 * 4 / 8 / 1024, //PKM_ETC1_RGB (4 bpp) -Compressed-
|
||||
512 * 512 * 4 / 8 / 1024, //PKM_ETC2_RGB (4 bpp) -Compressed-
|
||||
512 * 512 * 8 / 8 / 1024, //PKM_ETC2_EAC_RGBA (8 bpp) -Compressed-
|
||||
512 * 512 * 4 / 8 / 1024, //KTX_ETC1_RGB (4 bpp) -Compressed-
|
||||
512 * 512 * 4 / 8 / 1024, //KTX_ETC2_RGB (4 bpp) -Compressed-
|
||||
512 * 512 * 8 / 8 / 1024, //KTX_ETC2_EAC_RGBA (8 bpp) -Compressed-
|
||||
512 * 512 * 8 / 8 / 1024, //ASTC_4x4_LDR (8 bpp) -Compressed-
|
||||
512 * 512 * 2 / 8 / 1024, //ASTC_8x8_LDR (2 bpp) -Compressed-
|
||||
512 * 512 * 4 / 8 / 1024, //PVR_PVRT_RGB (4 bpp) -Compressed-
|
||||
512 * 512 * 4 / 8 / 1024, //PVR_PVRT_RGBA (4 bpp) -Compressed-
|
||||
}
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
// Update
|
||||
|
||||
if raylib.IsKeyPressed(raylib.KeyDown) {
|
||||
selectedFormat++
|
||||
if selectedFormat >= numTextures {
|
||||
selectedFormat = 0
|
||||
}
|
||||
} else if raylib.IsKeyPressed(raylib.KeyUp) {
|
||||
selectedFormat--
|
||||
if selectedFormat < 0 {
|
||||
selectedFormat = numTextures - 1
|
||||
}
|
||||
} else if raylib.IsKeyPressed(raylib.KeyRight) {
|
||||
if selectedFormat < numTextures/2 {
|
||||
selectedFormat += numTextures / 2
|
||||
}
|
||||
} else if raylib.IsKeyPressed(raylib.KeyLeft) {
|
||||
if selectedFormat >= numTextures/2 {
|
||||
selectedFormat -= numTextures / 2
|
||||
}
|
||||
}
|
||||
|
||||
// Draw
|
||||
|
||||
raylib.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
|
||||
// Draw rectangles
|
||||
for i := 0; i < numTextures; i++ {
|
||||
if i == selectedFormat {
|
||||
raylib.DrawRectangleRec(selectRecs[i], raylib.SkyBlue)
|
||||
raylib.DrawRectangleLines(selectRecs[i].X, selectRecs[i].Y, selectRecs[i].Width, selectRecs[i].Height, raylib.Blue)
|
||||
raylib.DrawText(formatText[i], selectRecs[i].X+selectRecs[i].Width/2-raylib.MeasureText(formatText[i], 10)/2, selectRecs[i].Y+11, 10, raylib.DarkBlue)
|
||||
} else {
|
||||
raylib.DrawRectangleRec(selectRecs[i], raylib.LightGray)
|
||||
raylib.DrawRectangleLines(selectRecs[i].X, selectRecs[i].Y, selectRecs[i].Width, selectRecs[i].Height, raylib.Gray)
|
||||
raylib.DrawText(formatText[i], selectRecs[i].X+selectRecs[i].Width/2-raylib.MeasureText(formatText[i], 10)/2, selectRecs[i].Y+11, 10, raylib.DarkGray)
|
||||
}
|
||||
}
|
||||
|
||||
// Draw selected texture
|
||||
if sonic[selectedFormat].ID != 0 {
|
||||
raylib.DrawTexture(sonic[selectedFormat], 350, -10, raylib.White)
|
||||
} else {
|
||||
raylib.DrawRectangleLines(488, 165, 200, 110, raylib.DarkGray)
|
||||
raylib.DrawText("FORMAT", 550, 180, 20, raylib.Maroon)
|
||||
raylib.DrawText("NOT SUPPORTED", 500, 210, 20, raylib.Maroon)
|
||||
raylib.DrawText("ON YOUR GPU", 520, 240, 20, raylib.Maroon)
|
||||
}
|
||||
|
||||
raylib.DrawText("Select texture format (use cursor keys):", 40, 10, 10, raylib.DarkGray)
|
||||
raylib.DrawText("Required GPU memory size (VRAM):", 40, 427, 10, raylib.DarkGray)
|
||||
raylib.DrawText(fmt.Sprintf("%4.0d KB", textureSizes[selectedFormat]), 240, 420, 20, raylib.DarkBlue)
|
||||
|
||||
raylib.EndDrawing()
|
||||
}
|
||||
|
||||
for i := 0; i < numTextures; i++ {
|
||||
raylib.UnloadTexture(sonic[i])
|
||||
}
|
||||
|
||||
raylib.CloseWindow()
|
||||
}
|
Before Width: | Height: | Size: 114 KiB |
|
@ -22,7 +22,7 @@ func main() {
|
|||
screenHeight := int32(450)
|
||||
|
||||
//raylib.SetConfigFlags(raylib.FlagVsyncHint)
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - particles trail blending")
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - particles blending")
|
||||
|
||||
// Particles pool, reuse them!
|
||||
mouseTail := make([]particle, maxParticles)
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
|
@ -12,10 +12,10 @@ func main() {
|
|||
|
||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||
|
||||
// Load RAW image data (512x512, 32bit RGBA, no file header)
|
||||
sonicRaw := raylib.LoadImageRaw("texture_formats/sonic_R8G8B8A8.raw", 512, 512, raylib.UncompressedR8g8b8a8, 0)
|
||||
sonic := raylib.LoadTextureFromImage(sonicRaw) // Upload CPU (RAM) image to GPU (VRAM)
|
||||
raylib.UnloadImage(sonicRaw) // Unload CPU (RAM) image data
|
||||
// Load RAW image data (384x512, 32bit RGBA, no file header)
|
||||
fudesumiRaw := raylib.LoadImageRaw("texture_formats/fudesumi.raw", 384, 512, raylib.UncompressedR8g8b8a8, 0)
|
||||
fudesumi := raylib.LoadTextureFromImage(fudesumiRaw) // Upload CPU (RAM) image to GPU (VRAM)
|
||||
raylib.UnloadImage(fudesumiRaw) // Unload CPU (RAM) image data
|
||||
|
||||
// Generate a checked texture by code (1024x1024 pixels)
|
||||
width := 1024
|
||||
|
@ -27,9 +27,9 @@ func main() {
|
|||
for y := 0; y < height; y++ {
|
||||
for x := 0; x < width; x++ {
|
||||
if ((x/32+y/32)/1)%2 == 0 {
|
||||
pixels[y*height+x] = raylib.DarkBlue
|
||||
pixels[y*height+x] = raylib.Orange
|
||||
} else {
|
||||
pixels[y*height+x] = raylib.SkyBlue
|
||||
pixels[y*height+x] = raylib.Gold
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,18 +46,18 @@ func main() {
|
|||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
|
||||
raylib.DrawTexture(checked, screenWidth/2-checked.Width/2, screenHeight/2-checked.Height/2, raylib.Fade(raylib.White, 0.3))
|
||||
raylib.DrawTexture(sonic, 330, -20, raylib.White)
|
||||
raylib.DrawTexture(checked, screenWidth/2-checked.Width/2, screenHeight/2-checked.Height/2, raylib.Fade(raylib.White, 0.5))
|
||||
raylib.DrawTexture(fudesumi, 430, -30, raylib.White)
|
||||
|
||||
raylib.DrawText("CHECKED TEXTURE ", 84, 100, 30, raylib.DarkBlue)
|
||||
raylib.DrawText("GENERATED by CODE", 72, 164, 30, raylib.DarkBlue)
|
||||
raylib.DrawText("and RAW IMAGE LOADING", 46, 226, 30, raylib.DarkBlue)
|
||||
raylib.DrawText("CHECKED TEXTURE ", 84, 100, 30, raylib.Brown)
|
||||
raylib.DrawText("GENERATED by CODE", 72, 164, 30, raylib.Brown)
|
||||
raylib.DrawText("and RAW IMAGE LOADING", 46, 226, 30, raylib.Brown)
|
||||
|
||||
raylib.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadTexture(sonic) // Texture unloading
|
||||
raylib.UnloadTexture(checked) // Texture unloading
|
||||
raylib.UnloadTexture(fudesumi) // Texture unloading
|
||||
raylib.UnloadTexture(checked) // Texture unloading
|
||||
|
||||
raylib.CloseWindow()
|
||||
}
|
||||
|
|
BIN
examples/textures/raw_data/texture_formats/fudesumi.raw
Normal file
Before Width: | Height: | Size: 83 KiB |
|
@ -1,9 +1,16 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const (
|
||||
maxFrameSpeed = 15
|
||||
minFrameSpeed = 1
|
||||
)
|
||||
|
||||
func main() {
|
||||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
@ -11,47 +18,70 @@ func main() {
|
|||
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture loading and drawing")
|
||||
|
||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||
guybrush := raylib.LoadTexture("guybrush.png") // Texture loading
|
||||
scarfy := raylib.LoadTexture("scarfy.png") // Texture loading
|
||||
|
||||
position := raylib.NewVector2(350.0, 240.0)
|
||||
frameRec := raylib.NewRectangle(0, 0, guybrush.Width/7, guybrush.Height)
|
||||
position := raylib.NewVector2(350.0, 280.0)
|
||||
frameRec := raylib.NewRectangle(0, 0, scarfy.Width/6, scarfy.Height)
|
||||
currentFrame := int32(0)
|
||||
|
||||
framesCounter := 0
|
||||
framesSpeed := 8 // Number of spritesheet frames shown by second
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
if raylib.IsKeyPressed(raylib.KeyRight) {
|
||||
framesCounter++
|
||||
|
||||
if framesCounter >= (60 / framesSpeed) {
|
||||
framesCounter = 0
|
||||
currentFrame++
|
||||
|
||||
if currentFrame > 6 {
|
||||
if currentFrame > 5 {
|
||||
currentFrame = 0
|
||||
}
|
||||
|
||||
frameRec.X = currentFrame * guybrush.Width / 7
|
||||
frameRec.X = currentFrame * scarfy.Width / 6
|
||||
}
|
||||
|
||||
if raylib.IsKeyPressed(raylib.KeyRight) {
|
||||
framesSpeed++
|
||||
} else if raylib.IsKeyPressed(raylib.KeyLeft) {
|
||||
framesSpeed--
|
||||
}
|
||||
|
||||
if framesSpeed > maxFrameSpeed {
|
||||
framesSpeed = maxFrameSpeed
|
||||
} else if framesSpeed < minFrameSpeed {
|
||||
framesSpeed = minFrameSpeed
|
||||
}
|
||||
|
||||
raylib.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
|
||||
raylib.DrawTexture(guybrush, 35, 40, raylib.White)
|
||||
raylib.DrawRectangleLines(35, 40, guybrush.Width, guybrush.Height, raylib.Lime)
|
||||
raylib.DrawTexture(scarfy, 15, 40, raylib.White)
|
||||
raylib.DrawRectangleLines(15, 40, scarfy.Width, scarfy.Height, raylib.Lime)
|
||||
raylib.DrawRectangleLines(15+frameRec.X, 40+frameRec.Y, frameRec.Width, frameRec.Height, raylib.Red)
|
||||
|
||||
raylib.DrawTextureRec(guybrush, frameRec, position, raylib.White) // Draw part of the texture
|
||||
raylib.DrawText("FRAME SPEED: ", 165, 210, 10, raylib.DarkGray)
|
||||
raylib.DrawText(fmt.Sprintf("%02d FPS", framesSpeed), 575, 210, 10, raylib.DarkGray)
|
||||
raylib.DrawText("PRESS RIGHT/LEFT KEYS to CHANGE SPEED!", 290, 240, 10, raylib.DarkGray)
|
||||
|
||||
raylib.DrawRectangleLines(35+frameRec.X, 40+frameRec.Y, frameRec.Width, frameRec.Height, raylib.Red)
|
||||
for i := 0; i < maxFrameSpeed; i++ {
|
||||
if i < framesSpeed {
|
||||
raylib.DrawRectangle(int32(250+21*i), 205, 20, 20, raylib.Red)
|
||||
}
|
||||
raylib.DrawRectangleLines(int32(250+21*i), 205, 20, 20, raylib.Maroon)
|
||||
}
|
||||
|
||||
raylib.DrawText("PRESS RIGHT KEY TO", 540, 310, 10, raylib.Gray)
|
||||
raylib.DrawText("CHANGE DRAWING RECTANGLE", 520, 330, 10, raylib.Gray)
|
||||
raylib.DrawTextureRec(scarfy, frameRec, position, raylib.White) // Draw part of the texture
|
||||
|
||||
raylib.DrawText("Guybrush Ulysses Threepwood,", 100, 300, 10, raylib.Gray)
|
||||
raylib.DrawText("main character of the Monkey Island series", 80, 320, 10, raylib.Gray)
|
||||
raylib.DrawText("of computer adventure games by LucasArts.", 80, 340, 10, raylib.Gray)
|
||||
raylib.DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth-200, screenHeight-20, 10, raylib.Gray)
|
||||
|
||||
raylib.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadTexture(guybrush)
|
||||
raylib.UnloadTexture(scarfy)
|
||||
|
||||
raylib.CloseWindow()
|
||||
}
|
||||
|
|
BIN
examples/textures/rectangle/scarfy.png
Normal file
After Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 83 KiB |
|
@ -11,10 +11,10 @@ func main() {
|
|||
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] examples - texture source and destination rectangles")
|
||||
|
||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||
guybrush := raylib.LoadTexture("guybrush.png") // Texture loading
|
||||
scarfy := raylib.LoadTexture("scarfy.png") // Texture loading
|
||||
|
||||
frameWidth := guybrush.Width / 7
|
||||
frameHeight := guybrush.Height
|
||||
frameWidth := scarfy.Width / 7
|
||||
frameHeight := scarfy.Height
|
||||
|
||||
// NOTE: Source rectangle (part of the texture to use for drawing)
|
||||
sourceRec := raylib.NewRectangle(0, 0, int32(frameWidth), int32(frameHeight))
|
||||
|
@ -43,15 +43,17 @@ func main() {
|
|||
// destRec defines the rectangle where our texture part will fit (scaling it to fit)
|
||||
// origin defines the point of the texture used as reference for rotation and scaling
|
||||
// rotation defines the texture rotation (using origin as rotation point)
|
||||
raylib.DrawTexturePro(guybrush, sourceRec, destRec, origin, rotation, raylib.White)
|
||||
raylib.DrawTexturePro(scarfy, sourceRec, destRec, origin, rotation, raylib.White)
|
||||
|
||||
raylib.DrawLine(destRec.X, 0, destRec.X, screenHeight, raylib.Gray)
|
||||
raylib.DrawLine(0, destRec.Y, screenWidth, destRec.Y, raylib.Gray)
|
||||
|
||||
raylib.DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth-200, screenHeight-20, 10, raylib.Gray)
|
||||
|
||||
raylib.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadTexture(guybrush)
|
||||
raylib.UnloadTexture(scarfy)
|
||||
|
||||
raylib.CloseWindow()
|
||||
}
|
||||
|
|
BIN
examples/textures/srcrec_dstrec/scarfy.png
Normal file
After Width: | Height: | Size: 32 KiB |