Jump to content
  • Advertisement
Sign in to follow this  
Daaark

OpenGL What's wrong with this code? (multitex)

This topic is 4843 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This is my first attempt at multitexuring, and I can't get it to work. I've been playing about with it all afternoon. At first I tried to do a quick double pass by drawing everything twice, but my second lightmap layer never showed. Now I install GLEE, and I look at the example that came with the gdnet opengl book to see what the options are, they are the same thgn I was using doing double passes. And I get the same result. I get just my diffuse texture showing, and not any of my light maps. I know my lightmaps are good, because I made them in deled, and it used multitex to render them in the viewport, as you can see here: CLICKY Also, I know my lightmaps are loaded into GL properly, as I can render with them fine if I pretend they are my diffuse textures.
glNewList(displaylist,GL_COMPILE);                
                
        glAlphaFunc(GL_GREATER, 0.5f);
        glEnable(GL_ALPHA_TEST);
        
        glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
        glEnable(GL_BLEND);
        
        glEnable(GL_DEPTH_TEST);
                
        for (int m = 0; m < materials; ++m)
        {            
            //set up the textures for the material
            glActiveTexture(GL_TEXTURE0);
            glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);
            glBindTexture(GL_TEXTURE_2D,tex[mat[m].dif].GetTexObj());
            
            glActiveTexture(GL_TEXTURE1);
            glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
            glBindTexture(GL_TEXTURE_2D,tex[mat[m].lit].GetTexObj());            
            
            //go through all the objects, and draw
            //any triangles that use this material
        	glBegin(GL_TRIANGLES);
        	for (int i = 0; i < objects; ++i)
        	{
                for (int j = 0; j < obj.triangles; ++j)
                {
                    if (obj.tri[j].mat == m)
                    {
                    	glNormal3fv(obj.tri[j].normal.v);                    	
                    	glMultiTexCoord2fv(GL_TEXTURE0,obj.tri[j].uvwdif[0]);
                    	glMultiTexCoord2fv(GL_TEXTURE1,obj.tri[j].uvwlit[0]);
                    	glVertex3fv(obj.vtx[obj.tri[j].vtx[0]].v);
                        glMultiTexCoord2fv(GL_TEXTURE0,obj.tri[j].uvwdif[1]);
                    	glMultiTexCoord2fv(GL_TEXTURE1,obj.tri[j].uvwlit[1]);
                    	glVertex3fv(obj.vtx[obj.tri[j].vtx[1]].v);
                    	glMultiTexCoord2fv(GL_TEXTURE0,obj.tri[j].uvwdif[2]);
                    	glMultiTexCoord2fv(GL_TEXTURE1,obj.tri[j].uvwlit[2]);
                    	glVertex3fv(obj.vtx[obj.tri[j].vtx[2]].v);
                    }
                }
        	}        	
        	glEnd();
        }        
    glEndList();

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Kalidor
Is texturing enabled on both texture units?
I love you! :)

A simple glEnable() did the trick... but then why didn't it work when I was multipassing? hmm...

Thanks alot!

Share this post


Link to post
Share on other sites
You probably have the depth func at GL_LESS, which prevents the second pass to show. Use GL_LEQUAL instead.

Share this post


Link to post
Share on other sites
Okay. Now That's I've got this working. What is it that I need to look into so I can render the scene onto a texture and display it on those screens? I'm not even sure where to begin looking.

What I'm thinking is, I can copy the frame buffer onto the screen texture? Isn't there a render to texture command or extension? Or do I need to make some special kind of buffer or something?

Share this post


Link to post
Share on other sites
glCopyTexImage2D() or glCopyTexSubImage2D() does the trick. You can use render to texture and pbuffers(which are a pain in the ass), and I don't know in which state the much more flexible and easy FBOs are right now(last time I checked, they were beta in NVidia). But glCopyTexImage2D() is not too slow, and you probably don't need to render the scene in very high resolution if you want to display it on stadium boards.

Share this post


Link to post
Share on other sites
Okay, well it's compiling. [razz]

But so far I'm just making a black texture. Do I have to specify all mip map levels?

I'm trying this, before I clear my buffer, to catch the last frame.

glBindTexture(GL_TEXTURE_2D,Map.GetTexture(nScreenTex));
glCopyTexImage2D(GL_TEXTURE_2D,0,GL_RGB,0,0,128,128,0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


-edit- That was working, it was just too dark, but it's fixed now. However it's only copying a portion of my screen, the lower left I think. When I make the 128x128 part the size of the screen it doesn't work at all. So I seem to be doing something else wrong?

Will my x*x framebuffer not get scaled into the x*x texture?

[Edited by - Vampyre_Dark on August 13, 2005 7:28:05 PM]

Share this post


Link to post
Share on other sites
I was able to get better results by making the screen texture 512x512, and grabbing the center of the screen into it, but the view will keep shrinking as I increase the resolution. [headshake]

Doesn't look that bad for now thought, just need to resize the screens on the side to preseve the aspect ratio of the texture. I'll probably call it a day. Thanks everyone for the help.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!