Update C sources, add new functions and rename package to
This commit is contained in:
parent
391c25482d
commit
08aa518a46
156 changed files with 34542 additions and 19573 deletions
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue