Skip to content

Commit ec97bb9

Browse files
WildBeast114514WildBeast114514
andauthored
fix(tools): display issue of camera (#54)
* feat(tools): migration of cyber visualizer on jetson * Clean up Qt5 installation and add dependencies Remove old Qt5 installation and update dependencies. * Revert "feat: refactor common file API (#39)" This reverts commit 40c9f7d. * fix(tools): display issue of camera --------- Co-authored-by: WildBeast114514 <[email protected]>
1 parent 24ee078 commit ec97bb9

File tree

2 files changed

+73
-28
lines changed

2 files changed

+73
-28
lines changed

modules/tools/visualizer/plane.cc

Lines changed: 69 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
std::shared_ptr<Texture> Plane::NullTextureObj;
2020

2121
Plane::Plane(const std::shared_ptr<Texture>& t)
22-
: RenderableObject(4, 4), texture_id_(0), texture_(t) {}
22+
: RenderableObject(6, 4), texture_id_(0), texture_(t) {}
2323

2424
bool Plane::FillVertexBuffer(GLfloat* pBuffer) {
2525
if (texture_ == nullptr || !texture_->isDirty()) {
@@ -30,33 +30,53 @@ bool Plane::FillVertexBuffer(GLfloat* pBuffer) {
3030
glBindTexture(GL_TEXTURE_2D, texture_id_);
3131
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3232
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
33-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
34-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
33+
// Clamp to edge for ES/core profile compatibility
34+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
35+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3536

36-
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, texture_->width(),
37-
texture_->height(), 0, texture_->texture_format(),
38-
GL_UNSIGNED_BYTE, texture_->data());
37+
// Prefer base internal formats for ES/core compatibility and match channels
38+
GLenum fmt = texture_->texture_format();
39+
GLint internal_fmt = (fmt == GL_RGBA) ? GL_RGBA : GL_RGB;
40+
glTexImage2D(GL_TEXTURE_2D, 0, internal_fmt, texture_->width(),
41+
texture_->height(), 0, fmt, GL_UNSIGNED_BYTE,
42+
texture_->data());
3943

4044
glBindTexture(GL_TEXTURE_2D, 0);
4145

4246
texture_->removeDirty();
4347

44-
pBuffer[0] = -1.0f;
45-
pBuffer[1] = -1.0f;
46-
pBuffer[2] = 0.0f;
47-
pBuffer[3] = 0.0f;
48-
pBuffer[4] = 1.0f;
49-
pBuffer[5] = -1.0f;
50-
pBuffer[6] = 1.0f;
51-
pBuffer[7] = 0.0f;
52-
pBuffer[8] = 1.0f;
53-
pBuffer[9] = 1.0f;
54-
pBuffer[10] = 1.0f;
55-
pBuffer[11] = 1.0f;
56-
pBuffer[12] = -1.0f;
57-
pBuffer[13] = 1.0f;
58-
pBuffer[14] = 0.0f;
59-
pBuffer[15] = 1.0f;
48+
// Two CCW triangles forming a full-screen quad
49+
// Triangle 0: BL, BR, TR
50+
pBuffer[0] = -1.0f; // BL.x
51+
pBuffer[1] = -1.0f; // BL.y
52+
pBuffer[2] = 0.0f; // BL.u
53+
pBuffer[3] = 0.0f; // BL.v
54+
55+
pBuffer[4] = 1.0f; // BR.x
56+
pBuffer[5] = -1.0f; // BR.y
57+
pBuffer[6] = 1.0f; // BR.u
58+
pBuffer[7] = 0.0f; // BR.v
59+
60+
pBuffer[8] = 1.0f; // TR.x
61+
pBuffer[9] = 1.0f; // TR.y
62+
pBuffer[10] = 1.0f; // TR.u
63+
pBuffer[11] = 1.0f; // TR.v
64+
65+
// Triangle 1: BL, TR, TL
66+
pBuffer[12] = -1.0f; // BL.x
67+
pBuffer[13] = -1.0f; // BL.y
68+
pBuffer[14] = 0.0f; // BL.u
69+
pBuffer[15] = 0.0f; // BL.v
70+
71+
pBuffer[16] = 1.0f; // TR.x
72+
pBuffer[17] = 1.0f; // TR.y
73+
pBuffer[18] = 1.0f; // TR.u
74+
pBuffer[19] = 1.0f; // TR.v
75+
76+
pBuffer[20] = -1.0f; // TL.x
77+
pBuffer[21] = 1.0f; // TL.y
78+
pBuffer[22] = 0.0f; // TL.u
79+
pBuffer[23] = 1.0f; // TL.v
6080

6181
return true;
6282
}
@@ -82,12 +102,14 @@ void Plane::Draw(void) {
82102
glBindTexture(GL_TEXTURE_2D, texture_id_);
83103
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
84104
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
85-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
86-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
105+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
106+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
87107

88-
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, texture_->width(),
89-
texture_->height(), 0, texture_->texture_format(),
90-
GL_UNSIGNED_BYTE, texture_->data());
108+
GLenum fmt = texture_->texture_format();
109+
GLint internal_fmt = (fmt == GL_RGBA) ? GL_RGBA : GL_RGB;
110+
glTexImage2D(GL_TEXTURE_2D, 0, internal_fmt, texture_->width(),
111+
texture_->height(), 0, fmt, GL_UNSIGNED_BYTE,
112+
texture_->data());
91113

92114
glBindTexture(GL_TEXTURE_2D, 0);
93115

@@ -104,6 +126,26 @@ void Plane::Draw(void) {
104126

105127
glActiveTexture(GL_TEXTURE0);
106128
glBindTexture(GL_TEXTURE_2D, texture_id_);
129+
// Avoid culling artifacts on some platforms by temporarily disabling
130+
// face culling while drawing the screen-aligned quad.
131+
GLboolean cull_enabled = glIsEnabled(GL_CULL_FACE);
132+
if (cull_enabled) {
133+
glDisable(GL_CULL_FACE);
134+
}
107135
RenderableObject::Draw();
136+
if (cull_enabled) {
137+
glEnable(GL_CULL_FACE);
138+
}
108139
glBindTexture(GL_TEXTURE_2D, 0);
109140
}
141+
142+
void Plane::SetupExtraUniforms(void) {
143+
// Ensure sampler uses texture unit 0
144+
if (shader_program_) {
145+
shader_program_->setUniformValue("u_texture", 0);
146+
// Backward compatibility: if shader still uses 'texture' as uniform name
147+
// (older shader), try to set it too.
148+
shader_program_->setUniformValue("texture", 0);
149+
}
150+
}
151+

modules/tools/visualizer/plane.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,19 @@ class Plane : public RenderableObject {
4343
}
4444
}
4545

46-
GLenum GetPrimitiveType(void) const override { return GL_QUADS; }
46+
// Use triangles to avoid culling flipping issues on triangle strips
47+
GLenum GetPrimitiveType(void) const override { return GL_TRIANGLES; }
4748
GLsizei texWidth(void) const { return texture_->width(); }
4849
GLsizei texHeight(void) const { return texture_->height(); }
4950

5051
protected:
5152
bool FillVertexBuffer(GLfloat* pBuffer) override;
5253
void Draw(void) override;
5354
void SetupAllAttrPointer(void) override;
55+
void SetupExtraUniforms(void) override;
5456

5557
private:
5658
GLuint texture_id_;
5759
std::shared_ptr<Texture> texture_;
5860
};
61+

0 commit comments

Comments
 (0)