I want to implement colorkey feature in opengl for my texture, as far as i understood now, it is not supported by opengl, so the idea would be to make two for loop for w and h of the texture and check for each pixels is they match color key, if yes then make alpha 0 otherwise make alpha 255, but how to implement that?
for i := 0 to textimage.w do begin for j := 0 to teximage.h do begin // read pixel? // set alpha?
Registriert: So Okt 21, 2007 14:16 Beiträge: 123
Programmiersprache: Delphi
Hi,
you can do that with a fragment shader. You set the projection mode to orthogonal and render a quad with the texture on it. Your vertex shader may look like this:
Now you can either copy the result to the main program using glReadPixels or into a texture using glCopyTexImage2D. To get the result in a texture, it is also possible/better to use Framebuffers.
you can do that with a fragment shader. You set the projection mode to orthogonal and render a quad with the texture on it. Your vertex shader may look like this:
Now you can either copy the result to the main program using glReadPixels or into a texture using glCopyTexImage2D. To get the result in a texture, it is also possible/better to use Framebuffers.
thanks for fast reply, but i forgot to mention, to do it without shaders, i want to use sdl + opengl only.
Registriert: So Okt 21, 2007 14:16 Beiträge: 123
Programmiersprache: Delphi
Hi,
if that's the case, I think it's easiest to load the whole picture into the main program using glReadPixels, then create an array with only the alpha data and then write this array back into the graphics memory using glDrawPixels with format parameter =GL_ALPHA. However, this needs a lot of bandwidth. Still, if you can use framebufferobjects and need the data in a texture, I suggest you to use one as it saves you another time-intensive copying procedure.
if that's the case, I think it's easiest to load the whole picture into the main program using glReadPixels, then create an array with only the alpha data and then write this array back into the graphics memory using glDrawPixels with format parameter =GL_ALPHA. However, this needs a lot of bandwidth. Still, if you can use framebufferobjects and need the data in a texture, I suggest you to use one as it saves you another time-intensive copying procedure.
thanks for reply again, well, i thinked like read pixel from texture and write to other new texture - with colorkey value changed to alpha? the problem is, i dont know how to read pixel from texture
Registriert: So Okt 21, 2007 14:16 Beiträge: 123
Programmiersprache: Delphi
As far as I know you can either draw the texture into the framebuffer from where you can read it using glReadPixels or use a framebuffer object, which is a framebuffer linked to a texture. I posted a link to a tutorial for framebufferobjects before, but if you can't read german, I suggest you to take a look at http://www.opengl.org/registry/specs/ARB/framebuffer_object.txt The only reason against FBOs is that some older graphics cards don't support this extension. In this case, you have to render the texture to the main frame buffer, read it via glReadPixels, create the alpha data, write the alpha data back to the frame buffer and copy the contents of the framebuffer back into the texture. This procedure is definitely slower than using FBOs. As far as I know there is no other method to read and write into textures, but maybe I'm wrong.
EDIT: sorry, to write into a texture it is afaik most useful to use glTexImage2D, ignore what I wrote above.
Zuletzt geändert von Joni am Do Jun 17, 2010 13:32, insgesamt 1-mal geändert.
As far as I know you can either draw the texture into the framebuffer from where you can read it using glReadPixels or use a framebuffer object, which is a framebuffer linked to a texture. I posted a link to a tutorial for framebufferobjects before, but if you can't read german, I suggest you to take a look at http://www.opengl.org/registry/specs/ARB/framebuffer_object.txt The only reason against FBOs is that some older graphics cards don't support this extension. In this case, you have to render the texture to the main frame buffer, read it via glReadPixels, create the alpha data, write the alpha data back to the frame buffer and copy the contents of the framebuffer back into the texture. This procedure is definitely slower than using FBOs. As far as I know there is no other method to read and write into textures, but maybe I'm wrong.
thanks again but the better to use image editor and change background color to alpha
Mitglieder in diesem Forum: 0 Mitglieder und 3 Gäste
Du darfst keine neuen Themen in diesem Forum erstellen. Du darfst keine Antworten zu Themen in diesem Forum erstellen. Du darfst deine Beiträge in diesem Forum nicht ändern. Du darfst deine Beiträge in diesem Forum nicht löschen. Du darfst keine Dateianhänge in diesem Forum erstellen.