Webentwicklung – die besten Beiträge

WebGL - Clip Space | Pixel Space?

// Renderer Beispiel
 render(){
       const s2  = new Square(300, 100, 70, [0, 1, 1, 1]);
       s2.setup(this.context, this.program); 
       s2.render(this.program, this.context, deltaTime);

       this.vertexManager.draw(3, 0, 4, 100, 100, 0, [0,0,1,1]);
 }
// 

export class Square extends Renderable {
    constructor (x, y, size, color) {
        super();
        this.x = x;
        this.y = y;
        this.size = size;
        this.color = color;
        this.vertices = new Float32Array([
            -size / 2, -size / 2,
            size / 2, -size / 2,
            size / 2, size / 2,
            -size / 2, size / 2,
        ]);
        this.vertexBuffer = null;
        this.colorBuffer = null;
        this.transformationMatrix = createIdentityMatrix3();
    }

    setup (gl, program) {
        this.vertexBuffer = gl.createBuffer();
        gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
        gl.bufferData(gl.ARRAY_BUFFER, this.vertices,  gl.STATIC_DRAW);
    }

    updateTransformationMatrix (x, y, scaleX, scaleY, angle) {
        const translationMatrix = createTranslationMatrix(x, y);
        const rotationMatrix = createRotationMatrix(angle);
        const scalingMatrix = createScalingMatrix(scaleX, scaleY);

        // Combine the matrices: translation * rotation * scaling
        const combinedMatrix = multiplyMatrices(rotationMatrix,          multiplyMatrices(translationMatrix, scalingMatrix));

        // Save the transformation matrix
        this.transformationMatrix = combinedMatrix;
    }


    render (program, gl, camera, deltaTime) {
        gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);

        // Re-enable the vertex attribute array
        const positionLocation = gl.getAttribLocation(program, 'a_position');
        gl.enableVertexAttribArray(positionLocation);
        gl.vertexAttribPointer(positionLocation, 2, gl.FLOAT, false, 0, 0);

        const colorLocation = gl.getUniformLocation(program, 'u_color');
        gl.uniform4fv(colorLocation, this.color);

        const matrixLocation = gl.getUniformLocation(program, 'u_matrix');
        this.updateTransformationMatrix(this.x, this.y, 1.0, 1.0,  0);
        gl.uniformMatrix3fv(matrixLocation, false, this.transformationMatrix);

        gl.drawArrays(gl.TRIANGLE_FAN, 0, this.vertices.length / 2 + 1);
    }
}

export default class VertexManager {
    constructor (gl, program) {
        this.gl = gl;
        this.program = program;
        this.buffers = new Map();
        this.initBuffers();
    }

    initBuffers () {
        this.createBuffer(BUFFER_TYPES.CIRCLE, createPolygonVertices(64, 1));
        this.createBuffer(BUFFER_TYPES.SQUARE, new Float32Array([
            -0.5, -0.5,
            0.5, -0.5,
            0.5, 0.5,
            -0.5, 0.5,
        ]));
    ....
    }

    createBuffer (type, vertices) {
        const buffer = this.gl.createBuffer();
        this.gl.bindBuffer(this.gl.ARRAY_BUFFER, buffer);
        this.gl.bufferData(this.gl.ARRAY_BUFFER, vertices, this.gl.STATIC_DRAW);
        this.buffers.set(type, { buffer, vertexCount: vertices.length / 2 });
    }

    draw (type, x, y, scaleX, scaleY, rotation, color) {
        const { buffer, vertexCount } = this.buffers.get(type);

        this.gl.bindBuffer(this.gl.ARRAY_BUFFER, buffer);

        // Re-enable the vertex attribute array
        const positionLocation = this.gl.getAttribLocation(this.program, 'a_position');
        this.gl.enableVertexAttribArray(positionLocation);
        this.gl.vertexAttribPointer(positionLocation, 2, this.gl.FLOAT, false, 0, 0);

        // Setup the color
        const colorLocation = this.gl.getUniformLocation(this.program, 'u_color');
        this.gl.uniform4fv(colorLocation, color);

        const matrixLocation = this.gl.getUniformLocation(this.program, 'u_matrix');
        // Create transformation matrices directly in pixel space
        const translationMatrix = createTranslationMatrix(x, y);
        const rotationMatrix = createRotationMatrix(rotation);
        const scalingMatrix = createScalingMatrix(scaleX, scaleY);

        // Combine them: translationMatrix * rotationMatrix * scalingMatrix
        const combinedMatrix = multiplyMatrices(rotationMatrix, multiplyMatrices(translationMatrix, scalingMatrix));

        // Pass the transformation matrix to the shader
        this.gl.uniformMatrix3fv(matrixLocation, false, combinedMatrix);

        this.gl.drawArrays(this.gl.TRIANGLE_FAN, 0, vertexCount);
    }
}

Meine Frage ist, warum mein Quadrat korrekt im Pixel-Space gerendert wird, während die draw-Operation in meinem VertexManager Clip-Space zeichnet, obwohl beide denselben Shader verwenden. Ich habe das Problem schon seit Stunden versucht zu lösen. Hat jemand eine Lösung oder einen Hinweis, was ich möglicherweise falsch mache?

Bild zum Beitrag
JavaScript, Code, OpenGL, Webentwicklung

Richtige Formatierung bei HTML und CSS?

Ich habe eine Frage. Ich arbeite gerade als Anfänger an einer Website und habe folgendes Problem.

So sieht die Website eigentlich aus :

So sieht sie aus nach der ersten Skalierung mit responsive Webdesign (wo nach alles richtig ist.):

Doch wenn ich ein weiteres mal skalieren möchte passiert folgender Fehler (Es soll so wie auf dem zweiten Bild aussehen nur kleiner):

HTML: <!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="style.css" type="text/css">
  <title>ToDo List</title>
</head>
<body>
  <header class="site-header">
    <form action="action_page.php" method="post">
      <input type="text" id="todo-box" name="box-input" placeholder="Aufgabe eingeben" required maxlength="50" class="todo-input">
      <input type="reset" class="todo-reset todo-reset-submit">
      <input type="submit" class="todo-submit" class="todo-reset-submit">
    </form>
  </header>
  <nav class="site-nav">
  </nav>
  <main class="site-main">
    <h2>ToDo</h2>
    <p class="todo-point">Müll rausbringen</p>
    <p class="todo-point">Zimmer aufräumen</p>
    <p class="todo-point">12345678901234567890123456789012345678901234567890</p>
  </main>
  <footer class="site-footer">
  </footer>
</body>
</html>
CSS: .site-header
{
  display: flex;
  justify-content: center;
  margin-bottom: 40px;
  margin-top: 20px;
}
.todo-input
{
  font-size: 20px;
  width: 180px;
  padding-left: 5px;
}
.todo-input::placeholder
{
  color: black;
}
.todo-reset, .todo-submit
{
  width: 150px;
  font-size: 20px;
  border: none;
  cursor: pointer;
}
.todo-input, .todo-reset, .todo-submit
{
  border-radius: 5px;
  background-color: rgb(251, 255, 0);
  border: none;
  height: 45px;
  transition: background-color 0.3s;
}
.todo-input:hover, .todo-reset:hover, .todo-submit:hover
{
  background-color: rgb(213, 216, 13);
}
.site-main
{
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 20px;
}
.site-footer
{
  margin-top: 60px;
  display: flex;
  justify-content: center;
}
p.todo-point
{
  margin: 3px 0;
  padding: 2px;
  border: 1mm solid black;
  border-radius: 10px;
}
@media (max-width: 520px)
{
  .todo-input
  {
    width: 480px;
    margin: 0 5px 5px 5px;
  }
  .todo-reset, .todo-submit
  {
    width: 240px;
    margin: 0 0 4px 4px;
  }
  p.todo-point
  {
    font-size: 19px;
  }
}
@media (max-width: 500px)
{
  .site-header
  {
    justify-self: unset;
  }
  .todo-input
  {
    display: flex;
    justify-content: center;
    width: 400px;
    margin: 0 5px 5px 5px;
  }
  .todo-reset-sumbit
  {
    display: flex;
    justify-content: center;
    width: 200px;
    margin: 0 0 4px 4px;
  }
}
Bild zum Beitrag
HTML, Webseite, CSS, Webdesign, Webentwicklung, Visual Studio Code

Meistgelesene Beiträge zum Thema Webentwicklung