Skip to content

Commit

Permalink
feat: added opengl backend demo
Browse files Browse the repository at this point in the history
  • Loading branch information
samthakur587 committed Jul 31, 2024
1 parent fa413a4 commit 34edb13
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 4 deletions.
63 changes: 61 additions & 2 deletions getting_start.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 3,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -493,6 +493,65 @@
"print(glsl_code)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"from src.backend.Opengl import *"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"shader main {\n",
" vertex {\n",
" input vec3 position;\n",
" input vec2 texCoord;\n",
" input vec2 vTexCoord;\n",
" output vec2 vTexCoord;\n",
"\n",
" output vec4 fragColor;\n",
"\n",
"\n",
"\n",
" void main() {\n",
" vTexCoord = texCoord;\n",
" gl_Position = vec4(position, 1.0);\n",
" }\n",
" }\n",
" fragment {\n",
"\n",
"\n",
" float marblePattern(vec2 uv) {\n",
" return (0.5 + (0.5 * sin(((10.0 * uv.x) + iTime))));\n",
" }\n",
" void main() {\n",
" color = vec3(marblePattern(vTexCoord), 0.0, 0.0);\n",
" fragColor = vec4(color, 1.0);\n",
" }\n",
" }\n",
"}\n",
"\n"
]
}
],
"source": [
"lexer = Lexer(glsl_code)\n",
"parser = Parser(lexer.tokens)\n",
"ast = parser.parse()\n",
"codegen = CrossglCodeGen()\n",
"cross_code = codegen.generate(ast)\n",
"print(cross_code)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -629,7 +688,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 2,
"metadata": {},
"outputs": [
{
Expand Down
1 change: 0 additions & 1 deletion src/translator/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def skip_comments(self):
self.eat(self.current_token[0])

def eat(self, token_type):
print(f"eat: {self.current_token[0]}, {self.current_token[1]}")
if self.current_token[0] == token_type:
self.pos += 1
self.current_token = (
Expand Down
5 changes: 4 additions & 1 deletion testing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import unittest
import os
from src.translator.lexer import Lexer
from src.translator.parser import Parser
from src.translator.codegen import (
Expand Down Expand Up @@ -31,8 +32,10 @@ def print_ast(node, indent=0):


class TestCodeGeneration(unittest.TestCase):
os.makedirs("test", exist_ok=True)

def setUp(self):
with open("test/test.cgl", "r") as f:
with open("examples/PerlinNoise.cgl", "r") as f:
self.code = f.read()

lexer = Lexer(self.code)
Expand Down

0 comments on commit 34edb13

Please sign in to comment.