Skip to content

Commit

Permalink
Add screenshot
Browse files Browse the repository at this point in the history
  • Loading branch information
rlj1202 committed May 7, 2018
1 parent 1e1c641 commit 7c6cc90
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Original article is [https://realhet.wordpress.com/2015/09/02/bitmap-logic-simul

The application is implemented with OpenGL.

## Screenshots
![](screenshots/2018_05_07_0.png)

## How does it work?
### Rules
Usage is very simple. Draw circuit in your favorate image editor, and load the image!
Expand Down Expand Up @@ -82,3 +85,5 @@ OR gate can be constructed using two wires merged.
- [x] File refresh per some certain time
- [x] Load and save configuration
- [ ] Optimization(performance, memory)
- [ ] Gate and wire viewr(overlay)
- [ ] User Interface
37 changes: 23 additions & 14 deletions cmd/BitmapLogicSimulator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,6 @@ func main() {

log.Printf("config : %v\n", *c)

imgFile, err := os.Open(c.FileName)
if err != nil {
panic(err)
}

watcher, err := fsnotify.NewWatcher()
defer watcher.Close()
if err != nil {
Expand Down Expand Up @@ -213,8 +208,10 @@ func main() {
log.Println("process image")

// load image
loadImage(imgFile)
imgFile.Close()
err = loadImage(c.FileName)
if err != nil {
panic(err)
}

// start simulation
width, height := window.GetSize()
Expand All @@ -225,16 +222,16 @@ func main() {

gl.Clear(gl.COLOR_BUFFER_BIT)

// file refresh
select {
case event := <-watcher.Events:
if event.Name == c.FileName {
if event.Op&fsnotify.Create == fsnotify.Create || event.Op&fsnotify.Write == fsnotify.Write {
log.Println("file refreshed.")

imgFile, err := os.Open(event.Name)
if err == nil {
loadImage(imgFile)
imgFile.Close()
err := loadImage(event.Name)
if err != nil {
log.Println(err)
}
}
}
Expand All @@ -243,26 +240,36 @@ func main() {
default:
}

// draw bitmap from current state
updateOverlayTex()

// render bitmap
gl.ActiveTexture(gl.TEXTURE0)
gl.BindTexture(gl.TEXTURE_2D, texId)
gl.ActiveTexture(gl.TEXTURE1)
gl.BindTexture(gl.TEXTURE_2D, overlayTex)
gl.DrawArrays(gl.TRIANGLE_STRIP, 0, 6)

// simulate
for i := 0; i < c.SimulationsPerFrame; i++ {
simulator.Simulate()
}

// display
window.SwapBuffers()
}
}

func loadImage(imgFile *os.File) {
func loadImage(imgFileName string) error {
imgFile, err := os.Open(imgFileName)
defer imgFile.Close()
if err != nil {
return err
}

img, _, err := image.Decode(imgFile)
if err != nil {
panic(err)
return err
}

if texId == 0 {
Expand All @@ -272,7 +279,7 @@ func loadImage(imgFile *os.File) {
}
err = loadTexture(img)
if err != nil {
panic(err)
return err
}

simulator.LoadImage(img)
Expand Down Expand Up @@ -302,6 +309,8 @@ func loadImage(imgFile *os.File) {

updateScaleMat(float32(width), float32(height), cameraZoom)
updateCameraLocMat()

return nil
}

func updateScaleMat(x, y, zoom float32) {
Expand Down
Binary file added screenshots/2018_05_07_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7c6cc90

Please sign in to comment.