Update C sources, add new functions and rename package to

This commit is contained in:
Milan Nikolic 2018-10-08 18:56:34 +02:00
parent 391c25482d
commit 08aa518a46
156 changed files with 34542 additions and 19573 deletions

View file

@ -8,42 +8,42 @@ func main() {
screenWidth := int32(800)
screenHeight := int32(450)
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture loading and drawing")
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture loading and drawing")
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
cat := raylib.LoadImage("cat.png") // Load image in CPU memory (RAM)
raylib.ImageCrop(cat, raylib.NewRectangle(100, 10, 280, 380)) // Crop an image piece
raylib.ImageFlipHorizontal(cat) // Flip cropped image horizontally
raylib.ImageResize(cat, 150, 200) // Resize flipped-cropped image
cat := rl.LoadImage("cat.png") // Load image in CPU memory (RAM)
rl.ImageCrop(cat, rl.NewRectangle(100, 10, 280, 380)) // Crop an image piece
rl.ImageFlipHorizontal(cat) // Flip cropped image horizontally
rl.ImageResize(cat, 150, 200) // Resize flipped-cropped image
parrots := raylib.LoadImage("parrots.png") // Load image in CPU memory (RAM)
parrots := rl.LoadImage("parrots.png") // Load image in CPU memory (RAM)
// Draw one image over the other with a scaling of 1.5f
raylib.ImageDraw(parrots, cat, raylib.NewRectangle(0, 0, float32(cat.Width), float32(cat.Height)), raylib.NewRectangle(30, 40, float32(cat.Width)*1.5, float32(cat.Height)*1.5))
raylib.ImageCrop(parrots, raylib.NewRectangle(0, 50, float32(parrots.Width), float32(parrots.Height-100))) // Crop resulting image
rl.ImageDraw(parrots, cat, rl.NewRectangle(0, 0, float32(cat.Width), float32(cat.Height)), rl.NewRectangle(30, 40, float32(cat.Width)*1.5, float32(cat.Height)*1.5))
rl.ImageCrop(parrots, rl.NewRectangle(0, 50, float32(parrots.Width), float32(parrots.Height-100))) // Crop resulting image
raylib.UnloadImage(cat) // Unload image from RAM
rl.UnloadImage(cat) // Unload image from RAM
texture := raylib.LoadTextureFromImage(parrots) // Image converted to texture, uploaded to GPU memory (VRAM)
raylib.UnloadImage(parrots) // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM
texture := rl.LoadTextureFromImage(parrots) // Image converted to texture, uploaded to GPU memory (VRAM)
rl.UnloadImage(parrots) // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM
raylib.SetTargetFPS(60)
rl.SetTargetFPS(60)
for !raylib.WindowShouldClose() {
raylib.BeginDrawing()
for !rl.WindowShouldClose() {
rl.BeginDrawing()
raylib.ClearBackground(raylib.RayWhite)
rl.ClearBackground(rl.RayWhite)
raylib.DrawTexture(texture, screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2-40, raylib.White)
raylib.DrawRectangleLines(screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2-40, texture.Width, texture.Height, raylib.DarkGray)
rl.DrawTexture(texture, screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2-40, rl.White)
rl.DrawRectangleLines(screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2-40, texture.Width, texture.Height, rl.DarkGray)
raylib.DrawText("We are drawing only one texture from various images composed!", 240, 350, 10, raylib.DarkGray)
raylib.DrawText("Source images have been cropped, scaled, flipped and copied one over the other.", 190, 370, 10, raylib.DarkGray)
rl.DrawText("We are drawing only one texture from various images composed!", 240, 350, 10, rl.DarkGray)
rl.DrawText("Source images have been cropped, scaled, flipped and copied one over the other.", 190, 370, 10, rl.DarkGray)
raylib.EndDrawing()
rl.EndDrawing()
}
raylib.UnloadTexture(texture)
rl.UnloadTexture(texture)
raylib.CloseWindow()
rl.CloseWindow()
}

View file

@ -10,85 +10,85 @@ func main() {
screenWidth := 800
screenHeight := 450
raylib.InitWindow(int32(screenWidth), int32(screenHeight), "raylib [textures] example - procedural images generation")
rl.InitWindow(int32(screenWidth), int32(screenHeight), "raylib [textures] example - procedural images generation")
verticalGradient := raylib.GenImageGradientV(screenWidth, screenHeight, raylib.Red, raylib.Blue)
horizontalGradient := raylib.GenImageGradientH(screenWidth, screenHeight, raylib.Red, raylib.Blue)
radialGradient := raylib.GenImageGradientRadial(screenWidth, screenHeight, 0, raylib.White, raylib.Black)
checked := raylib.GenImageChecked(screenWidth, screenHeight, 32, 32, raylib.Red, raylib.Blue)
whiteNoise := raylib.GenImageWhiteNoise(screenWidth, screenHeight, 0.5)
perlinNoise := raylib.GenImagePerlinNoise(screenWidth, screenHeight, 50, 50, 4.0)
cellular := raylib.GenImageCellular(screenWidth, screenHeight, 32)
verticalGradient := rl.GenImageGradientV(screenWidth, screenHeight, rl.Red, rl.Blue)
horizontalGradient := rl.GenImageGradientH(screenWidth, screenHeight, rl.Red, rl.Blue)
radialGradient := rl.GenImageGradientRadial(screenWidth, screenHeight, 0, rl.White, rl.Black)
checked := rl.GenImageChecked(screenWidth, screenHeight, 32, 32, rl.Red, rl.Blue)
whiteNoise := rl.GenImageWhiteNoise(screenWidth, screenHeight, 0.5)
perlinNoise := rl.GenImagePerlinNoise(screenWidth, screenHeight, 50, 50, 4.0)
cellular := rl.GenImageCellular(screenWidth, screenHeight, 32)
textures := make([]raylib.Texture2D, numTextures)
textures[0] = raylib.LoadTextureFromImage(verticalGradient)
textures[1] = raylib.LoadTextureFromImage(horizontalGradient)
textures[2] = raylib.LoadTextureFromImage(radialGradient)
textures[3] = raylib.LoadTextureFromImage(checked)
textures[4] = raylib.LoadTextureFromImage(whiteNoise)
textures[5] = raylib.LoadTextureFromImage(perlinNoise)
textures[6] = raylib.LoadTextureFromImage(cellular)
textures := make([]rl.Texture2D, numTextures)
textures[0] = rl.LoadTextureFromImage(verticalGradient)
textures[1] = rl.LoadTextureFromImage(horizontalGradient)
textures[2] = rl.LoadTextureFromImage(radialGradient)
textures[3] = rl.LoadTextureFromImage(checked)
textures[4] = rl.LoadTextureFromImage(whiteNoise)
textures[5] = rl.LoadTextureFromImage(perlinNoise)
textures[6] = rl.LoadTextureFromImage(cellular)
// Unload image data (CPU RAM)
raylib.UnloadImage(verticalGradient)
raylib.UnloadImage(horizontalGradient)
raylib.UnloadImage(radialGradient)
raylib.UnloadImage(checked)
raylib.UnloadImage(whiteNoise)
raylib.UnloadImage(perlinNoise)
raylib.UnloadImage(cellular)
rl.UnloadImage(verticalGradient)
rl.UnloadImage(horizontalGradient)
rl.UnloadImage(radialGradient)
rl.UnloadImage(checked)
rl.UnloadImage(whiteNoise)
rl.UnloadImage(perlinNoise)
rl.UnloadImage(cellular)
currentTexture := 0
raylib.SetTargetFPS(60)
rl.SetTargetFPS(60)
for !raylib.WindowShouldClose() {
if raylib.IsMouseButtonPressed(raylib.MouseLeftButton) {
for !rl.WindowShouldClose() {
if rl.IsMouseButtonPressed(rl.MouseLeftButton) {
currentTexture = (currentTexture + 1) % numTextures // Cycle between the textures
}
raylib.BeginDrawing()
rl.BeginDrawing()
raylib.ClearBackground(raylib.RayWhite)
rl.ClearBackground(rl.RayWhite)
raylib.DrawTexture(textures[currentTexture], 0, 0, raylib.White)
rl.DrawTexture(textures[currentTexture], 0, 0, rl.White)
raylib.DrawRectangle(30, 400, 325, 30, raylib.Fade(raylib.SkyBlue, 0.5))
raylib.DrawRectangleLines(30, 400, 325, 30, raylib.Fade(raylib.White, 0.5))
raylib.DrawText("MOUSE LEFT BUTTON to CYCLE PROCEDURAL TEXTURES", 40, 410, 10, raylib.White)
rl.DrawRectangle(30, 400, 325, 30, rl.Fade(rl.SkyBlue, 0.5))
rl.DrawRectangleLines(30, 400, 325, 30, rl.Fade(rl.White, 0.5))
rl.DrawText("MOUSE LEFT BUTTON to CYCLE PROCEDURAL TEXTURES", 40, 410, 10, rl.White)
switch currentTexture {
case 0:
raylib.DrawText("VERTICAL GRADIENT", 560, 10, 20, raylib.RayWhite)
rl.DrawText("VERTICAL GRADIENT", 560, 10, 20, rl.RayWhite)
break
case 1:
raylib.DrawText("HORIZONTAL GRADIENT", 540, 10, 20, raylib.RayWhite)
rl.DrawText("HORIZONTAL GRADIENT", 540, 10, 20, rl.RayWhite)
break
case 2:
raylib.DrawText("RADIAL GRADIENT", 580, 10, 20, raylib.LightGray)
rl.DrawText("RADIAL GRADIENT", 580, 10, 20, rl.LightGray)
break
case 3:
raylib.DrawText("CHECKED", 680, 10, 20, raylib.RayWhite)
rl.DrawText("CHECKED", 680, 10, 20, rl.RayWhite)
break
case 4:
raylib.DrawText("WHITE NOISE", 640, 10, 20, raylib.Red)
rl.DrawText("WHITE NOISE", 640, 10, 20, rl.Red)
break
case 5:
raylib.DrawText("PERLIN NOISE", 630, 10, 20, raylib.RayWhite)
rl.DrawText("PERLIN NOISE", 630, 10, 20, rl.RayWhite)
break
case 6:
raylib.DrawText("CELLULAR", 670, 10, 20, raylib.RayWhite)
rl.DrawText("CELLULAR", 670, 10, 20, rl.RayWhite)
break
default:
break
}
raylib.EndDrawing()
rl.EndDrawing()
}
for _, t := range textures {
raylib.UnloadTexture(t)
rl.UnloadTexture(t)
}
raylib.CloseWindow()
rl.CloseWindow()
}

View file

@ -11,57 +11,57 @@ func main() {
screenWidth := int32(800)
screenHeight := int32(450)
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture from image.Image")
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture from image.Image")
r, err := os.Open("raylib_logo.png")
if err != nil {
raylib.TraceLog(raylib.LogError, err.Error())
rl.TraceLog(rl.LogError, err.Error())
}
defer r.Close()
img, err := png.Decode(r)
if err != nil {
raylib.TraceLog(raylib.LogError, err.Error())
rl.TraceLog(rl.LogError, err.Error())
}
// Create raylib.Image from Go image.Image and create texture
im := raylib.NewImageFromImage(img)
texture := raylib.LoadTextureFromImage(im)
// Create rl.Image from Go image.Image and create texture
im := rl.NewImageFromImage(img)
texture := rl.LoadTextureFromImage(im)
// Unload CPU (RAM) image data
raylib.UnloadImage(im)
rl.UnloadImage(im)
raylib.SetTargetFPS(60)
rl.SetTargetFPS(60)
for !raylib.WindowShouldClose() {
if raylib.IsKeyPressed(raylib.KeyS) {
rimg := raylib.GetTextureData(texture)
for !rl.WindowShouldClose() {
if rl.IsKeyPressed(rl.KeyS) {
rimg := rl.GetTextureData(texture)
f, err := os.Create("image_saved.png")
if err != nil {
raylib.TraceLog(raylib.LogError, err.Error())
rl.TraceLog(rl.LogError, err.Error())
}
err = png.Encode(f, rimg.ToImage())
if err != nil {
raylib.TraceLog(raylib.LogError, err.Error())
rl.TraceLog(rl.LogError, err.Error())
}
f.Close()
}
raylib.BeginDrawing()
rl.BeginDrawing()
raylib.ClearBackground(raylib.RayWhite)
rl.ClearBackground(rl.RayWhite)
raylib.DrawText("PRESS S TO SAVE IMAGE FROM TEXTURE", 20, 20, 12, raylib.LightGray)
raylib.DrawTexture(texture, screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2, raylib.White)
raylib.DrawText("this IS a texture loaded from an image.Image!", 285, 370, 10, raylib.Gray)
rl.DrawText("PRESS S TO SAVE IMAGE FROM TEXTURE", 20, 20, 12, rl.LightGray)
rl.DrawTexture(texture, screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2, rl.White)
rl.DrawText("this IS a texture loaded from an image.Image!", 285, 370, 10, rl.Gray)
raylib.EndDrawing()
rl.EndDrawing()
}
raylib.UnloadTexture(texture)
rl.UnloadTexture(texture)
raylib.CloseWindow()
rl.CloseWindow()
}

View file

@ -8,30 +8,30 @@ func main() {
screenWidth := int32(800)
screenHeight := int32(450)
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - image loading")
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] example - image loading")
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
image := raylib.LoadImage("raylib_logo.png") // Loaded in CPU memory (RAM)
texture := raylib.LoadTextureFromImage(image) // Image converted to texture, GPU memory (VRAM)
image := rl.LoadImage("raylib_logo.png") // Loaded in CPU memory (RAM)
texture := rl.LoadTextureFromImage(image) // Image converted to texture, GPU memory (VRAM)
raylib.UnloadImage(image) // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM
rl.UnloadImage(image) // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM
raylib.SetTargetFPS(60)
rl.SetTargetFPS(60)
for !raylib.WindowShouldClose() {
raylib.BeginDrawing()
for !rl.WindowShouldClose() {
rl.BeginDrawing()
raylib.ClearBackground(raylib.RayWhite)
rl.ClearBackground(rl.RayWhite)
raylib.DrawTexture(texture, screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2, raylib.White)
rl.DrawTexture(texture, screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2, rl.White)
raylib.DrawText("this IS a texture loaded from an image!", 300, 370, 10, raylib.Gray)
rl.DrawText("this IS a texture loaded from an image!", 300, 370, 10, rl.Gray)
raylib.EndDrawing()
rl.EndDrawing()
}
raylib.UnloadTexture(texture)
rl.UnloadTexture(texture)
raylib.CloseWindow()
rl.CloseWindow()
}

View file

@ -33,31 +33,31 @@ func main() {
screenWidth := int32(800)
screenHeight := int32(450)
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - image processing")
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] example - image processing")
image := raylib.LoadImage("parrots.png") // Loaded in CPU memory (RAM)
raylib.ImageFormat(image, raylib.UncompressedR8g8b8a8) // Format image to RGBA 32bit (required for texture update)
texture := raylib.LoadTextureFromImage(image) // Image converted to texture, GPU memory (VRAM)
image := rl.LoadImage("parrots.png") // Loaded in CPU memory (RAM)
rl.ImageFormat(image, rl.UncompressedR8g8b8a8) // Format image to RGBA 32bit (required for texture update)
texture := rl.LoadTextureFromImage(image) // Image converted to texture, GPU memory (VRAM)
currentProcess := None
textureReload := false
selectRecs := make([]raylib.Rectangle, numProcesses)
selectRecs := make([]rl.Rectangle, numProcesses)
for i := 0; i < numProcesses; i++ {
selectRecs[i] = raylib.NewRectangle(40, 50+32*float32(i), 150, 30)
selectRecs[i] = rl.NewRectangle(40, 50+32*float32(i), 150, 30)
}
raylib.SetTargetFPS(60)
rl.SetTargetFPS(60)
for !raylib.WindowShouldClose() {
if raylib.IsKeyPressed(raylib.KeyDown) {
for !rl.WindowShouldClose() {
if rl.IsKeyPressed(rl.KeyDown) {
currentProcess++
if currentProcess > 7 {
currentProcess = 0
}
textureReload = true
} else if raylib.IsKeyPressed(raylib.KeyUp) {
} else if rl.IsKeyPressed(rl.KeyUp) {
currentProcess--
if currentProcess < 0 {
currentProcess = 7
@ -66,70 +66,70 @@ func main() {
}
if textureReload {
raylib.UnloadImage(image) // Unload current image data
image = raylib.LoadImage("parrots.png") // Re-load image data
rl.UnloadImage(image) // Unload current image data
image = rl.LoadImage("parrots.png") // Re-load image data
// NOTE: Image processing is a costly CPU process to be done every frame,
// If image processing is required in a frame-basis, it should be done
// with a texture and by shaders
switch currentProcess {
case ColorGrayscale:
raylib.ImageColorGrayscale(image)
rl.ImageColorGrayscale(image)
break
case ColorTint:
raylib.ImageColorTint(image, raylib.Green)
rl.ImageColorTint(image, rl.Green)
break
case ColorInvert:
raylib.ImageColorInvert(image)
rl.ImageColorInvert(image)
break
case ColorContrast:
raylib.ImageColorContrast(image, -40)
rl.ImageColorContrast(image, -40)
break
case ColorBrightness:
raylib.ImageColorBrightness(image, -80)
rl.ImageColorBrightness(image, -80)
break
case FlipVertical:
raylib.ImageFlipVertical(image)
rl.ImageFlipVertical(image)
break
case FlipHorizontal:
raylib.ImageFlipHorizontal(image)
rl.ImageFlipHorizontal(image)
break
default:
break
}
pixels := raylib.GetImageData(image) // Get pixel data from image (RGBA 32bit)
raylib.UpdateTexture(texture, pixels) // Update texture with new image data
pixels := rl.GetImageData(image) // Get pixel data from image (RGBA 32bit)
rl.UpdateTexture(texture, pixels) // Update texture with new image data
textureReload = false
}
raylib.BeginDrawing()
rl.BeginDrawing()
raylib.ClearBackground(raylib.RayWhite)
rl.ClearBackground(rl.RayWhite)
raylib.DrawText("IMAGE PROCESSING:", 40, 30, 10, raylib.DarkGray)
rl.DrawText("IMAGE PROCESSING:", 40, 30, 10, rl.DarkGray)
// Draw rectangles
for i := 0; i < numProcesses; i++ {
if i == currentProcess {
raylib.DrawRectangleRec(selectRecs[i], raylib.SkyBlue)
raylib.DrawRectangleLines(int32(selectRecs[i].X), int32(selectRecs[i].Y), int32(selectRecs[i].Width), int32(selectRecs[i].Height), raylib.Blue)
raylib.DrawText(processText[i], int32(selectRecs[i].X+selectRecs[i].Width/2)-raylib.MeasureText(processText[i], 10)/2, int32(selectRecs[i].Y)+11, 10, raylib.DarkBlue)
rl.DrawRectangleRec(selectRecs[i], rl.SkyBlue)
rl.DrawRectangleLines(int32(selectRecs[i].X), int32(selectRecs[i].Y), int32(selectRecs[i].Width), int32(selectRecs[i].Height), rl.Blue)
rl.DrawText(processText[i], int32(selectRecs[i].X+selectRecs[i].Width/2)-rl.MeasureText(processText[i], 10)/2, int32(selectRecs[i].Y)+11, 10, rl.DarkBlue)
} else {
raylib.DrawRectangleRec(selectRecs[i], raylib.LightGray)
raylib.DrawRectangleLines(int32(selectRecs[i].X), int32(selectRecs[i].Y), int32(selectRecs[i].Width), int32(selectRecs[i].Height), raylib.Gray)
raylib.DrawText(processText[i], int32(selectRecs[i].X+selectRecs[i].Width/2)-raylib.MeasureText(processText[i], 10)/2, int32(selectRecs[i].Y)+11, 10, raylib.DarkGray)
rl.DrawRectangleRec(selectRecs[i], rl.LightGray)
rl.DrawRectangleLines(int32(selectRecs[i].X), int32(selectRecs[i].Y), int32(selectRecs[i].Width), int32(selectRecs[i].Height), rl.Gray)
rl.DrawText(processText[i], int32(selectRecs[i].X+selectRecs[i].Width/2)-rl.MeasureText(processText[i], 10)/2, int32(selectRecs[i].Y)+11, 10, rl.DarkGray)
}
}
raylib.DrawTexture(texture, screenWidth-texture.Width-60, screenHeight/2-texture.Height/2, raylib.White)
raylib.DrawRectangleLines(screenWidth-texture.Width-60, screenHeight/2-texture.Height/2, texture.Width, texture.Height, raylib.Black)
rl.DrawTexture(texture, screenWidth-texture.Width-60, screenHeight/2-texture.Height/2, rl.White)
rl.DrawRectangleLines(screenWidth-texture.Width-60, screenHeight/2-texture.Height/2, texture.Width, texture.Height, rl.Black)
raylib.EndDrawing()
rl.EndDrawing()
}
raylib.UnloadTexture(texture)
rl.UnloadTexture(texture)
raylib.CloseWindow()
rl.CloseWindow()
}

View file

@ -8,55 +8,55 @@ func main() {
screenWidth := int32(800)
screenHeight := int32(450)
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - image text drawing")
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] example - image text drawing")
// TTF Font loading with custom generation parameters
var fontChars int32
font := raylib.LoadFontEx("fonts/KAISG.ttf", 64, 0, &fontChars)
font := rl.LoadFontEx("fonts/KAISG.ttf", 64, 0, &fontChars)
parrots := raylib.LoadImage("parrots.png") // Load image in CPU memory (RAM)
parrots := rl.LoadImage("parrots.png") // Load image in CPU memory (RAM)
// Draw over image using custom font
raylib.ImageDrawTextEx(parrots, raylib.NewVector2(20, 20), font, "[Parrots font drawing]", float32(font.BaseSize), 0, raylib.White)
rl.ImageDrawTextEx(parrots, rl.NewVector2(20, 20), font, "[Parrots font drawing]", float32(font.BaseSize), 0, rl.White)
texture := raylib.LoadTextureFromImage(parrots) // Image converted to texture, uploaded to GPU memory (VRAM)
texture := rl.LoadTextureFromImage(parrots) // Image converted to texture, uploaded to GPU memory (VRAM)
raylib.UnloadImage(parrots) // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM
rl.UnloadImage(parrots) // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM
position := raylib.NewVector2(float32(screenWidth)/2-float32(texture.Width)/2, float32(screenHeight)/2-float32(texture.Height)/2-20)
position := rl.NewVector2(float32(screenWidth)/2-float32(texture.Width)/2, float32(screenHeight)/2-float32(texture.Height)/2-20)
showFont := false
raylib.SetTargetFPS(60)
rl.SetTargetFPS(60)
for !raylib.WindowShouldClose() {
if raylib.IsKeyDown(raylib.KeySpace) {
for !rl.WindowShouldClose() {
if rl.IsKeyDown(rl.KeySpace) {
showFont = true
} else {
showFont = false
}
raylib.BeginDrawing()
rl.BeginDrawing()
raylib.ClearBackground(raylib.RayWhite)
rl.ClearBackground(rl.RayWhite)
if !showFont {
// Draw texture with text already drawn inside
raylib.DrawTextureV(texture, position, raylib.White)
rl.DrawTextureV(texture, position, rl.White)
// Draw text directly using sprite font
raylib.DrawTextEx(font, "[Parrots font drawing]", raylib.NewVector2(position.X+20, position.Y+20+280), float32(font.BaseSize), 0, raylib.White)
rl.DrawTextEx(font, "[Parrots font drawing]", rl.NewVector2(position.X+20, position.Y+20+280), float32(font.BaseSize), 0, rl.White)
} else {
raylib.DrawTexture(font.Texture, screenWidth/2-font.Texture.Width/2, 50, raylib.Black)
rl.DrawTexture(font.Texture, screenWidth/2-font.Texture.Width/2, 50, rl.Black)
}
raylib.DrawText("PRESS SPACE to SEE USED SPRITEFONT ", 290, 420, 10, raylib.DarkGray)
rl.DrawText("PRESS SPACE to SEE USED SPRITEFONT ", 290, 420, 10, rl.DarkGray)
raylib.EndDrawing()
rl.EndDrawing()
}
raylib.UnloadTexture(texture)
raylib.UnloadFont(font)
rl.UnloadTexture(texture)
rl.UnloadFont(font)
raylib.CloseWindow()
rl.CloseWindow()
}

View file

@ -8,24 +8,24 @@ func main() {
screenWidth := int32(800)
screenHeight := int32(450)
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture loading and drawing")
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture loading and drawing")
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
texture := raylib.LoadTexture("raylib_logo.png")
texture := rl.LoadTexture("raylib_logo.png")
raylib.SetTargetFPS(60)
rl.SetTargetFPS(60)
for !raylib.WindowShouldClose() {
raylib.BeginDrawing()
for !rl.WindowShouldClose() {
rl.BeginDrawing()
raylib.ClearBackground(raylib.RayWhite)
raylib.DrawTexture(texture, screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2, raylib.White)
raylib.DrawText("this IS a texture!", 360, 370, 10, raylib.Gray)
rl.ClearBackground(rl.RayWhite)
rl.DrawTexture(texture, screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2, rl.White)
rl.DrawText("this IS a texture!", 360, 370, 10, rl.Gray)
raylib.EndDrawing()
rl.EndDrawing()
}
raylib.UnloadTexture(texture)
rl.UnloadTexture(texture)
raylib.CloseWindow()
rl.CloseWindow()
}

View file

@ -9,8 +9,8 @@ const (
)
type particle struct {
Position raylib.Vector2
Color raylib.Color
Position rl.Vector2
Color rl.Color
Alpha float32
Size float32
Rotation float32
@ -21,31 +21,31 @@ func main() {
screenWidth := int32(800)
screenHeight := int32(450)
//raylib.SetConfigFlags(raylib.FlagVsyncHint)
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - particles blending")
//rl.SetConfigFlags(rl.FlagVsyncHint)
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] example - particles blending")
// Particles pool, reuse them!
mouseTail := make([]particle, maxParticles)
// Initialize particles
for i := 0; i < maxParticles; i++ {
mouseTail[i].Position = raylib.NewVector2(0, 0)
mouseTail[i].Color = raylib.NewColor(byte(raylib.GetRandomValue(0, 255)), byte(raylib.GetRandomValue(0, 255)), byte(raylib.GetRandomValue(0, 255)), 255)
mouseTail[i].Position = rl.NewVector2(0, 0)
mouseTail[i].Color = rl.NewColor(byte(rl.GetRandomValue(0, 255)), byte(rl.GetRandomValue(0, 255)), byte(rl.GetRandomValue(0, 255)), 255)
mouseTail[i].Alpha = 1.0
mouseTail[i].Size = float32(raylib.GetRandomValue(1, 30)) / 20.0
mouseTail[i].Rotation = float32(raylib.GetRandomValue(0, 360))
mouseTail[i].Size = float32(rl.GetRandomValue(1, 30)) / 20.0
mouseTail[i].Rotation = float32(rl.GetRandomValue(0, 360))
mouseTail[i].Active = false
}
gravity := float32(3.0)
smoke := raylib.LoadTexture("smoke.png")
smoke := rl.LoadTexture("smoke.png")
blending := raylib.BlendAlpha
blending := rl.BlendAlpha
raylib.SetTargetFPS(60)
rl.SetTargetFPS(60)
for !raylib.WindowShouldClose() {
for !rl.WindowShouldClose() {
// Update
// Activate one particle every frame and Update active particles
@ -56,7 +56,7 @@ func main() {
if !mouseTail[i].Active {
mouseTail[i].Active = true
mouseTail[i].Alpha = 1.0
mouseTail[i].Position = raylib.GetMousePosition()
mouseTail[i].Position = rl.GetMousePosition()
i = maxParticles
}
}
@ -74,50 +74,50 @@ func main() {
}
}
if raylib.IsKeyPressed(raylib.KeySpace) {
if blending == raylib.BlendAlpha {
blending = raylib.BlendAdditive
if rl.IsKeyPressed(rl.KeySpace) {
if blending == rl.BlendAlpha {
blending = rl.BlendAdditive
} else {
blending = raylib.BlendAlpha
blending = rl.BlendAlpha
}
}
// Draw
raylib.BeginDrawing()
rl.BeginDrawing()
raylib.ClearBackground(raylib.DarkGray)
rl.ClearBackground(rl.DarkGray)
raylib.BeginBlendMode(blending)
rl.BeginBlendMode(blending)
// Draw active particles
for i := 0; i < maxParticles; i++ {
if mouseTail[i].Active {
raylib.DrawTexturePro(
rl.DrawTexturePro(
smoke,
raylib.NewRectangle(0, 0, float32(smoke.Width), float32(smoke.Height)),
raylib.NewRectangle(mouseTail[i].Position.X, mouseTail[i].Position.Y, float32(smoke.Width)*mouseTail[i].Size, float32(smoke.Height)*mouseTail[i].Size),
raylib.NewVector2(float32(smoke.Width)*mouseTail[i].Size/2, float32(smoke.Height)*mouseTail[i].Size/2),
rl.NewRectangle(0, 0, float32(smoke.Width), float32(smoke.Height)),
rl.NewRectangle(mouseTail[i].Position.X, mouseTail[i].Position.Y, float32(smoke.Width)*mouseTail[i].Size, float32(smoke.Height)*mouseTail[i].Size),
rl.NewVector2(float32(smoke.Width)*mouseTail[i].Size/2, float32(smoke.Height)*mouseTail[i].Size/2),
mouseTail[i].Rotation,
raylib.Fade(mouseTail[i].Color, mouseTail[i].Alpha),
rl.Fade(mouseTail[i].Color, mouseTail[i].Alpha),
)
}
}
raylib.EndBlendMode()
rl.EndBlendMode()
raylib.DrawText("PRESS SPACE to CHANGE BLENDING MODE", 180, 20, 20, raylib.Black)
rl.DrawText("PRESS SPACE to CHANGE BLENDING MODE", 180, 20, 20, rl.Black)
if blending == raylib.BlendAlpha {
raylib.DrawText("ALPHA BLENDING", 290, screenHeight-40, 20, raylib.Black)
if blending == rl.BlendAlpha {
rl.DrawText("ALPHA BLENDING", 290, screenHeight-40, 20, rl.Black)
} else {
raylib.DrawText("ADDITIVE BLENDING", 280, screenHeight-40, 20, raylib.RayWhite)
rl.DrawText("ADDITIVE BLENDING", 280, screenHeight-40, 20, rl.RayWhite)
}
raylib.EndDrawing()
rl.EndDrawing()
}
raylib.UnloadTexture(smoke)
rl.UnloadTexture(smoke)
raylib.CloseWindow()
rl.CloseWindow()
}

View file

@ -8,56 +8,56 @@ func main() {
screenWidth := int32(800)
screenHeight := int32(450)
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture from raw data")
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture from raw data")
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
// 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
fudesumiRaw := rl.LoadImageRaw("texture_formats/fudesumi.raw", 384, 512, rl.UncompressedR8g8b8a8, 0)
fudesumi := rl.LoadTextureFromImage(fudesumiRaw) // Upload CPU (RAM) image to GPU (VRAM)
rl.UnloadImage(fudesumiRaw) // Unload CPU (RAM) image data
// Generate a checked texture by code (1024x1024 pixels)
width := 1024
height := 1024
// Dynamic memory allocation to store pixels data (Color type)
pixels := make([]raylib.Color, width*height)
pixels := make([]rl.Color, width*height)
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.Orange
pixels[y*height+x] = rl.Orange
} else {
pixels[y*height+x] = raylib.Gold
pixels[y*height+x] = rl.Gold
}
}
}
// Load pixels data into an image structure and create texture
checkedIm := raylib.LoadImageEx(pixels, int32(width), int32(height))
checked := raylib.LoadTextureFromImage(checkedIm)
raylib.UnloadImage(checkedIm) // Unload CPU (RAM) image data
checkedIm := rl.LoadImageEx(pixels, int32(width), int32(height))
checked := rl.LoadTextureFromImage(checkedIm)
rl.UnloadImage(checkedIm) // Unload CPU (RAM) image data
raylib.SetTargetFPS(60)
rl.SetTargetFPS(60)
for !raylib.WindowShouldClose() {
raylib.BeginDrawing()
for !rl.WindowShouldClose() {
rl.BeginDrawing()
raylib.ClearBackground(raylib.RayWhite)
rl.ClearBackground(rl.RayWhite)
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)
rl.DrawTexture(checked, screenWidth/2-checked.Width/2, screenHeight/2-checked.Height/2, rl.Fade(rl.White, 0.5))
rl.DrawTexture(fudesumi, 430, -30, rl.White)
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)
rl.DrawText("CHECKED TEXTURE ", 84, 100, 30, rl.Brown)
rl.DrawText("GENERATED by CODE", 72, 164, 30, rl.Brown)
rl.DrawText("and RAW IMAGE LOADING", 46, 226, 30, rl.Brown)
raylib.EndDrawing()
rl.EndDrawing()
}
raylib.UnloadTexture(fudesumi) // Texture unloading
raylib.UnloadTexture(checked) // Texture unloading
rl.UnloadTexture(fudesumi) // Texture unloading
rl.UnloadTexture(checked) // Texture unloading
raylib.CloseWindow()
rl.CloseWindow()
}

View file

@ -15,21 +15,21 @@ func main() {
screenWidth := int32(800)
screenHeight := int32(450)
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture loading and drawing")
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture loading and drawing")
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
scarfy := raylib.LoadTexture("scarfy.png") // Texture loading
scarfy := rl.LoadTexture("scarfy.png") // Texture loading
position := raylib.NewVector2(350.0, 280.0)
frameRec := raylib.NewRectangle(0, 0, float32(scarfy.Width/6), float32(scarfy.Height))
position := rl.NewVector2(350.0, 280.0)
frameRec := rl.NewRectangle(0, 0, float32(scarfy.Width/6), float32(scarfy.Height))
currentFrame := float32(0)
framesCounter := 0
framesSpeed := 8 // Number of spritesheet frames shown by second
raylib.SetTargetFPS(60)
rl.SetTargetFPS(60)
for !raylib.WindowShouldClose() {
for !rl.WindowShouldClose() {
framesCounter++
if framesCounter >= (60 / framesSpeed) {
@ -43,9 +43,9 @@ func main() {
frameRec.X = currentFrame * float32(scarfy.Width) / 6
}
if raylib.IsKeyPressed(raylib.KeyRight) {
if rl.IsKeyPressed(rl.KeyRight) {
framesSpeed++
} else if raylib.IsKeyPressed(raylib.KeyLeft) {
} else if rl.IsKeyPressed(rl.KeyLeft) {
framesSpeed--
}
@ -55,33 +55,33 @@ func main() {
framesSpeed = minFrameSpeed
}
raylib.BeginDrawing()
rl.BeginDrawing()
raylib.ClearBackground(raylib.RayWhite)
rl.ClearBackground(rl.RayWhite)
raylib.DrawTexture(scarfy, 15, 40, raylib.White)
raylib.DrawRectangleLines(15, 40, scarfy.Width, scarfy.Height, raylib.Lime)
raylib.DrawRectangleLines(15+int32(frameRec.X), 40+int32(frameRec.Y), int32(frameRec.Width), int32(frameRec.Height), raylib.Red)
rl.DrawTexture(scarfy, 15, 40, rl.White)
rl.DrawRectangleLines(15, 40, scarfy.Width, scarfy.Height, rl.Lime)
rl.DrawRectangleLines(15+int32(frameRec.X), 40+int32(frameRec.Y), int32(frameRec.Width), int32(frameRec.Height), rl.Red)
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)
rl.DrawText("FRAME SPEED: ", 165, 210, 10, rl.DarkGray)
rl.DrawText(fmt.Sprintf("%02d FPS", framesSpeed), 575, 210, 10, rl.DarkGray)
rl.DrawText("PRESS RIGHT/LEFT KEYS to CHANGE SPEED!", 290, 240, 10, rl.DarkGray)
for i := 0; i < maxFrameSpeed; i++ {
if i < framesSpeed {
raylib.DrawRectangle(int32(250+21*i), 205, 20, 20, raylib.Red)
rl.DrawRectangle(int32(250+21*i), 205, 20, 20, rl.Red)
}
raylib.DrawRectangleLines(int32(250+21*i), 205, 20, 20, raylib.Maroon)
rl.DrawRectangleLines(int32(250+21*i), 205, 20, 20, rl.Maroon)
}
raylib.DrawTextureRec(scarfy, frameRec, position, raylib.White) // Draw part of the texture
rl.DrawTextureRec(scarfy, frameRec, position, rl.White) // Draw part of the texture
raylib.DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth-200, screenHeight-20, 10, raylib.Gray)
rl.DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth-200, screenHeight-20, 10, rl.Gray)
raylib.EndDrawing()
rl.EndDrawing()
}
raylib.UnloadTexture(scarfy)
rl.UnloadTexture(scarfy)
raylib.CloseWindow()
rl.CloseWindow()
}

View file

@ -8,52 +8,52 @@ func main() {
screenWidth := int32(800)
screenHeight := int32(450)
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] examples - texture source and destination rectangles")
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] examples - texture source and destination rectangles")
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
scarfy := raylib.LoadTexture("scarfy.png") // Texture loading
scarfy := rl.LoadTexture("scarfy.png") // Texture loading
frameWidth := float32(scarfy.Width) / 7
frameHeight := float32(scarfy.Height)
// NOTE: Source rectangle (part of the texture to use for drawing)
sourceRec := raylib.NewRectangle(0, 0, frameWidth, frameHeight)
sourceRec := rl.NewRectangle(0, 0, frameWidth, frameHeight)
// NOTE: Destination rectangle (screen rectangle where drawing part of texture)
destRec := raylib.NewRectangle(float32(screenWidth)/2, float32(screenHeight)/2, frameWidth*2, frameHeight*2)
destRec := rl.NewRectangle(float32(screenWidth)/2, float32(screenHeight)/2, frameWidth*2, frameHeight*2)
// NOTE: Origin of the texture (rotation/scale point), it's relative to destination rectangle size
origin := raylib.NewVector2(float32(frameWidth), float32(frameHeight))
origin := rl.NewVector2(float32(frameWidth), float32(frameHeight))
rotation := float32(0)
raylib.SetTargetFPS(60)
rl.SetTargetFPS(60)
for !raylib.WindowShouldClose() {
for !rl.WindowShouldClose() {
// Update
rotation++
// Draw
raylib.BeginDrawing()
rl.BeginDrawing()
raylib.ClearBackground(raylib.RayWhite)
rl.ClearBackground(rl.RayWhite)
// NOTE: Using DrawTexturePro() we can easily rotate and scale the part of the texture we draw
// sourceRec defines the part of the texture we use for drawing
// 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(scarfy, sourceRec, destRec, origin, rotation, raylib.White)
rl.DrawTexturePro(scarfy, sourceRec, destRec, origin, rotation, rl.White)
raylib.DrawLine(int32(destRec.X), 0, int32(destRec.X), screenHeight, raylib.Gray)
raylib.DrawLine(0, int32(destRec.Y), screenWidth, int32(destRec.Y), raylib.Gray)
rl.DrawLine(int32(destRec.X), 0, int32(destRec.X), screenHeight, rl.Gray)
rl.DrawLine(0, int32(destRec.Y), screenWidth, int32(destRec.Y), rl.Gray)
raylib.DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth-200, screenHeight-20, 10, raylib.Gray)
rl.DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth-200, screenHeight-20, 10, rl.Gray)
raylib.EndDrawing()
rl.EndDrawing()
}
raylib.UnloadTexture(scarfy)
rl.UnloadTexture(scarfy)
raylib.CloseWindow()
rl.CloseWindow()
}

View file

@ -8,32 +8,32 @@ func main() {
screenWidth := int32(800)
screenHeight := int32(450)
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture to image")
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture to image")
image := raylib.LoadImage("raylib_logo.png") // Load image data into CPU memory (RAM)
texture := raylib.LoadTextureFromImage(image) // Image converted to texture, GPU memory (RAM -> VRAM)
raylib.UnloadImage(image) // Unload image data from CPU memory (RAM)
image := rl.LoadImage("raylib_logo.png") // Load image data into CPU memory (RAM)
texture := rl.LoadTextureFromImage(image) // Image converted to texture, GPU memory (RAM -> VRAM)
rl.UnloadImage(image) // Unload image data from CPU memory (RAM)
image = raylib.GetTextureData(texture) // Retrieve image data from GPU memory (VRAM -> RAM)
raylib.UnloadTexture(texture) // Unload texture from GPU memory (VRAM)
image = rl.GetTextureData(texture) // Retrieve image data from GPU memory (VRAM -> RAM)
rl.UnloadTexture(texture) // Unload texture from GPU memory (VRAM)
texture = raylib.LoadTextureFromImage(image) // Recreate texture from retrieved image data (RAM -> VRAM)
raylib.UnloadImage(image) // Unload retrieved image data from CPU memory (RAM)
texture = rl.LoadTextureFromImage(image) // Recreate texture from retrieved image data (RAM -> VRAM)
rl.UnloadImage(image) // Unload retrieved image data from CPU memory (RAM)
raylib.SetTargetFPS(60)
rl.SetTargetFPS(60)
for !raylib.WindowShouldClose() {
raylib.BeginDrawing()
for !rl.WindowShouldClose() {
rl.BeginDrawing()
raylib.ClearBackground(raylib.RayWhite)
rl.ClearBackground(rl.RayWhite)
raylib.DrawTexture(texture, screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2, raylib.White)
raylib.DrawText("this IS a texture loaded from an image!", 300, 370, 10, raylib.Gray)
rl.DrawTexture(texture, screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2, rl.White)
rl.DrawText("this IS a texture loaded from an image!", 300, 370, 10, rl.Gray)
raylib.EndDrawing()
rl.EndDrawing()
}
raylib.UnloadTexture(texture)
rl.UnloadTexture(texture)
raylib.CloseWindow()
rl.CloseWindow()
}