hello world

This commit is contained in:
2025-08-26 21:04:15 +02:00
parent 949d6722f0
commit 03a4b1133e
6 changed files with 483 additions and 413 deletions

831
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -15,5 +15,5 @@ gl = "0.14.0"
tobj = ">3.1.0"
image = "0.24.3"
nalgebra-glm = "0.17.0"
rand = "0.8.4"
rand = "0.9"
libc = "0.2.132"

View File

@@ -1,14 +0,0 @@
if exist source.zip (
del source.zip
)
"%~dp0/vendor/7za.exe" -tzip a source.zip ^
Cargo.lock ^
Cargo.toml ^
src ^
shaders ^
resources/* ^
-x!resources/helicopter.obj ^
-x!resources/lunarsurface.obj ^
-x!resources/.gitkeep
pause

View File

@@ -1,8 +1,7 @@
#version 430 core
#version 460 core
out vec4 color;
out layout(location=0) vec4 color;
void main()
{
void main() {
color = vec4(1.0f, 1.0f, 1.0f, 1.0f);
}
}

View File

@@ -1,8 +1,7 @@
#version 430 core
#version 460 core
in vec3 position;
in layout(location=0) vec3 position;
void main()
{
void main() {
gl_Position = vec4(position, 1.0f);
}
}

View File

@@ -27,9 +27,8 @@ use glutin::event_loop::ControlFlow;
// initial window size
const INITIAL_SCREEN_W: u32 = 800;
const INITIAL_SCREEN_H: u32 = 600;
// TODO: I used the funny number.
const VERTEX_ATTRIBUTE_INDEX: u32 = 3;
const DIMENSIONS: i32 = 2;
const VERTEX_ATTRIBUTE_INDEX: u32 = 0;
const DIMENSIONS: i32 = 3;
// == // Helper functions to make interacting with OpenGL a little bit prettier. You *WILL* need these! // == //
@@ -99,7 +98,6 @@ unsafe fn create_vao(vertices: &Vec<f32>, indices: &Vec<u32>) -> u32 {
);
gl::EnableVertexAttribArray(VERTEX_ATTRIBUTE_INDEX);
let mut index_buf_id = 0;
gl::GenBuffers(1, &mut index_buf_id);
gl::BindBuffer(gl::ELEMENT_ARRAY_BUFFER, index_buf_id);
@@ -110,8 +108,6 @@ unsafe fn create_vao(vertices: &Vec<f32>, indices: &Vec<u32>) -> u32 {
gl::STATIC_DRAW,
);
gl::DrawElements(gl::TRIANGLES, indices.len() as i32, gl::UNSIGNED_INT, std::ptr::null());
vao_id
}
@@ -185,11 +181,16 @@ fn main() {
// == // Set up your VAO around here
let vertices = vec![-1., 0., 1., 0.5];
let indices = vec![0, 1, 2, 1, 1, 3];
let vertices = vec![
-0.6, -0.6, 0.,
0.6, -0.6, 0.,
0., 0.6, 0.
];
let indices = vec![0, 1, 2];
let my_vao = unsafe {
create_vao(&vertices, &indices);
create_vao(&vertices, &indices)
};
println!("created vao!");
// let my_vao = unsafe { 1337 };
@@ -206,10 +207,6 @@ fn main() {
let simple_shader = unsafe {
shader::ShaderBuilder::new()
.attach_file("./shaders/simple.vert")
.link()
};
let simple_shader = unsafe {
shader::ShaderBuilder::new()
.attach_file("./shaders/simple.frag")
.link()
};
@@ -274,6 +271,14 @@ fn main() {
gl::Clear(gl::COLOR_BUFFER_BIT | gl::DEPTH_BUFFER_BIT);
// == // Issue the necessary gl:: commands to draw your scene here
simple_shader.activate();
gl::BindVertexArray(my_vao);
gl::DrawElements(
gl::TRIANGLES,
indices.len() as i32,
gl::UNSIGNED_INT,
std::ptr::null(),
);
}
// Display the new color buffer on the display