Skip to content

[BUG] OpenGL renderer does not correctly take into account color for box primitives #810

@mmacklin

Description

@mmacklin

Bug Description

When calling render_box() on the OpenGL visualizer it currently only hashes the extents and not the color, which means you can't draw multiple boxes of the same size with different colors, simple repro that should draw a red and blue box:

import warp as wp
import warp.render
import numpy as np


def test_opengl_renderer_boxes():
    """Test OpenGLRenderer by rendering a couple of boxes"""
    
    # Create the OpenGL renderer
    renderer = wp.render.OpenGLRenderer(
        title="Test Boxes",
        screen_width=800,
        screen_height=600,
        camera_pos=(5.0, 5.0, 5.0),
        camera_front=(-1.0, -1.0, -1.0),
        vsync=False
    )
    
    frame_count = 0
    max_frames = 1024  
    
    try:
        while renderer.is_running() and frame_count < max_frames:
            time = renderer.clock_time
            
            renderer.begin_frame(time)
            
            # Render first box - red, stationary
            renderer.render_box(
                name="box1",
                pos=(0.0, 1.0, 0.0),
                rot=wp.quat_identity(),
                extents=(1.0, 1.0, 1.0),
                color=(1.0, 0.0, 0.0)  # Red
            )
            
            # Render second box - blue, rotating
            rotation_angle = time * 2.0  # Rotate over time
            rotation_quat = wp.quat_from_axis_angle(
                wp.vec3(0.0, 1.0, 0.0), rotation_angle
            )
            
            renderer.render_box(
                name="box2", 
                pos=(3.0, 1.0, np.sin(time)),  # Move up and down
                rot=rotation_quat,
                extents=(1.0, 1.0, 1.0),
                color=(0.0, 0.0, 1.0)  # Blue
            )
            
            renderer.end_frame()
            frame_count += 1
            
    finally:
        # Clean up the renderer
        renderer.clear()
        renderer.close()


if __name__ == "__main__":
    test_opengl_renderer_boxes()

System Information

No response

Metadata

Metadata

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions