webgl added

This commit is contained in:
dongho
2024-08-31 22:39:25 +09:00
parent c6bb80ee5c
commit efbcdea403
5 changed files with 1291 additions and 2 deletions

View File

@ -1,4 +1,104 @@
/*use std::fmt::write;
use osmpbf::*;
*/
use yew::prelude::*;
#[function_component]
fn App() -> Html {
let counter = use_state(|| 0);
let onclick = {
let counter = counter.clone();
move |_| {
let value = *counter + 1;
counter.set(value);
}
};
html! {
<div>
<button {onclick}>{ "+1" }</button>
<p>{ *counter }</p>
</div>
}
}
fn main() {
yew::Render::<App>::new().render();
}
/*
const fn compileLinkProgram(vs: *const u8, vs_len: usize, fs: *const u8, fs_len: usize) -> i32 {
let test_val: i32 = 1;
test_val
}
const fn bind2DFloat32Data(data: *const f32, data_len: usize) -> i32 {
let test_val: i32 = 1;
test_val
}
pub fn glBindVertexArray(vao: i32) {
println!("glBindVertexArray");
}
pub fn glClearColor(r: f32, g: f32, b: f32, a:f32) {
println!("Clear Color");
}
pub fn glClear(mask: i32) {
println!("Clear");
}
pub fn glUseProgram(program: i32) {
println!("Using Program");
}
pub fn glDrawArrays(mode: i32, first: i32, last:i32) {
println!("Draw Arrays");
}
const COLOR_BUFFER_BIT: i32 = 16384;
const TRIANGLE_STRIP: i32 = 5;
pub fn run() {
const VS_SOURCE: &str = "attribute vec4 aVertexPosition; \
void main() { \
gl_Position = aVertexPosition; \
} \
;";
const FS_SOURCE: &str = "void main() { \
gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); \
} \
";
const POSITIONS: [f32; 8] = [0.5, 0.5, -0.5, 0.5, 0.5, -0.5, -0.5, -0.5];
const PROGRAM: i32 = compileLinkProgram(VS_SOURCE.as_ptr(), VS_SOURCE.len(), FS_SOURCE.as_ptr(), FS_SOURCE.len());
const VAO: i32 = bind2DFloat32Data(POSITIONS.as_ptr(), POSITIONS.len());
glBindVertexArray(VAO);
// Set clear color to black, fully opaqe
glClearColor(0.0, 0.0, 0.0, 1.0);
// Clear the color buffer with specified clear color
glClear(COLOR_BUFFER_BIT);
glUseProgram(PROGRAM);
{
const offset = 0;
cconst fn bind2DFloat32Data(data: *const f32, data_len: usize) -> i32 {
let test_val: i32 = 1;
test_val
}
const POSITIONS: [f32; 8] = [0.5, 0.5, -0.5, 0.5, 0.5, -0.5, -0.5, -0.5];
const PROGRAM: i32 = compileLinkProgram(VS_SOURCE.as_ptr(), VS_SOURCE.len(), FS_SOURCE.as_ptr(), FS_SOURCE.len());
const VAO: i32 = bind2DFloat32Data(POSITIONS, POSITIONS.len());onst vertexCount = 4;
gl.drawArrays(gl.TRIANGLE_STRIP, offset, vertexCount);
}
}
fn main() {
let reader = ElementReader::from_path(
@ -27,3 +127,4 @@ fn main() {
}
}
}
*/