0

I have webgl 3D scene with background image and few shapes with textures.
I want to add some lines and other shapes and apply on them default color which not affect the shapes with textures.
How can I do this?
this is what I have now:

gl.clearColor(0.0, 0.0, 0.0, 0.0); //alpha=0 for background img
gl.enable(gl.DEPTH_TEST);
genpfault
  • 51,148
  • 11
  • 85
  • 139
arii
  • 143
  • 2
  • 12

2 Answers2

2

I'm going to write the following in terms of calls as exposed by C interfaces (for sake of generity; the specification itself completely omits the gl… in front).

glClearColor selects the color to which the framebuffer is cleared upon a call of glClear(GL_COLOR_BUFFER_BIT | …). Without doing a glClear call it has no effect whatsoever.

glEnable(GL_DEPTH_TEST) enables depth testing for the drawing calls that follow.

want to add some lines and other shapes and apply on them default color … How can I do this?

Uh, just draw them.

which not affect the shapes with textures.

That's how OpenGL works anyway. OpenGL does not describe a scene. OpenGL is all about what's happening "in the moment". It just draws points, lines or triangles, one at a time, and the only "interference" is, that it overdraws pixels in the framebuffer.

Of course with a global state machine, altering state has an effect on everything that follows. So if you want to go back to the previous behavior you have to undo all the state changes you did for a particular drawing you did.

datenwolf
  • 159,371
  • 13
  • 185
  • 298
1

WebGL is by default composited into the webpage. That means clearing to 0,0,0,0 means the canvas is transparent the standard webpage CSS background color settings of the canvas itself or the elements behind it (<body>, <html>> etc are what that canvas will be blended with

You might find this answer helpful

https://stackoverflow.com/a/39354174/128511

Community
  • 1
  • 1
gman
  • 100,619
  • 31
  • 269
  • 393