Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Posts posted by ak09

  1. As an example, the SendMessage(hWnd, CB_GETCURSEL, 0, 0) function returns the selected index of a combo box.
    If my purpose is to read this index multiple times, I should call this function multiple times. Or don't I?

    Instead, is there an address where these kind of stuff are stored so I can and use it for making things easier?

  2. Hi, mhagain, thanks for the reply.
    Yeah, my hardware can't deal with that you mentioned.
    For the moment I'm wondering how good or bad is my current approach of copying a texture binded by some FBO into another binded by another FBO.
    The method consists in clearing the destination texture and drawing the first one to the second, so I can make the copy even if dealing with different sized textures.

  3. The manual says those are specified in basic machine units, which is most likely bytes, just like in other opengl functions. Have you tried passing zeros for offsets, and the size of your buffer in bytes for the size? It should copy the whole buffer.

    I tried every reasonable combination.
    Maybe it's important to say that I'm trying to copy an FBO to another (because I don't know if this function can deal with FBO's).


  4. From the specification,

    void *glCopyBufferSubData(enum readtarget, enum writetarget,
         intptr readoffset, intptr writeoffset, sizeiptr size);

                glCopyBufferSubData copies part of the data store attached to readtarget to the
                data store attached to writetarget. The number of basic machine units indicated by size
                is copied from the source, at offset readoffset to the destination at writeoffset,
                also in basic machine units.

    It's not very clear, however, what's the meaning if readoffset, writeoffset and size, and how should them be used.

            glBindFramebuffer(GL_COPY_READ_BUFFER, fboSrc);
            glBindFramebuffer(GL_COPY_WRITE_BUFFER, fboDst);
            glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER, ?, ?, ?);


    Any clue?


  5. Thanks for the replies.

    I assumed this is what he wants, for example to be able to do a 2D UI with nice 3D transitions.

    That's exactly what I want: be able to see my layers from different perspectives and choose one among them with a nice interface.

    However, I couldn't make it work yet. Tried both approaches, from Bob and Olof, but stills nothing.

    I don't know if I'm doing the calculations ok. Let me try to explain exactly how it's being done so far:

    The layer l1 is drawn over the layer l2. Every layer have it's own attributes, i.e, xPosition, yPosition, width, height, and angle, so I must (I guess) apply the properly transformations in the modelview matrix before each draw.

    As posted before, that's my perspective function, called before anything:


    void setPerspective(int w, int h)
        glViewport(0, 0, w, h);
        // gluOrtho2D(0, w, h, 0); (the old guy)
        gluPerspective(60.0, (GLfloat) w/(GLfloat) h, 0.001, 5000.0);
        ... (transformations suggested by you)



    And that's the mess with which my layer is drawn, working perfectly with ortho2D:


                setPerspective(dst->width, dst->height);
                   // Dest transformations
                glTranslatef(dst->cx, dst->cy, 0);  // cx = width/2   cy = height/2
                glRotatef(-dst->angle, 0, 0, 1);
                glTranslatef(-dst->cx, -dst->cy, 0);
                glTranslatef(-dst->x, -dst->y, 0.0f);
                   // Source transformations
                glTranslatef(src->x, src->y, 0.0f);
                glTranslatef(src->cx, src->cy, 0);
                glRotatef(src->angle, 0, 0, 1);
                glTranslatef(-src->cx, -src->cy, 0);
                glBindTexture(GL_TEXTURE_2D, src->texID;
                glTexCoord2f(0.0f, 1.0f);  glVertex2i(0,0);    
                glTexCoord2f(1.0f, 1.0f);  glVertex2i(src->width,0);  
                glTexCoord2f(1.0f, 0.0f);  glVertex2i(src->width,src->height);  
                glTexCoord2f(0.0f, 0.0f);  glVertex2i(0,src->height);
                glBindTexture(GL_TEXTURE_2D, 0);



  6. That is the job of the view matrix.


    A scaling and a translation will make sure that the coordinates in x/y-plane from 0,0 to w,h is mapped to the screen.

    Sorry, but this is a little vague to me.
    All I'm doing is making a perspective change before every texture draw — since they can have different sizes — with:

    void setPerspective(int w, int h)
        glViewport(0, 0, w, h);
        gluOrtho2D(0, w, h, 0);


    By replacing my gluOrtho2D with gluPerspective, what changes shoud I make and where?

  7. I'm drawing 2D, on different layers, dealing with real coordinates [(0,0), (screenWidth, screenHeight)] instead of the standard [-1,1]. And everything is ok when using gluOrtho2D(0, w, h, 0).

    However, I want to be able to render those layers in a 3D space, so the user can merge in the scene. The problem is: with gluPerspective, all my coordinates are changed, and for the reason I'd have to change them all in my code, this is strictly unwanted.

    So, is there a (simple) way to solve my thing?

  8.  I found that a simple fragment shader for that would be something like:


    uniform sampler2D Mtexture;
    void main()
        vec4 color = texture2D(Mtexture, gl_TexCoord[0].st);
        gl_FragColor = vec4(1.0 - color.r, 1.0 - color.g, 1.0 - color.b, color.a);

    And the OGL code:

        glBindFramebuffer(GL_FRAMEBUFFER, fbo);
        glColor4f(1, 1, 1, 1);
        glBindTexture(GL_TEXTURE_2D, tex);
        glTexCoord2f(0.0f, 1.0f);  glVertex2i(0,0);    
        glTexCoord2f(1.0f, 1.0f);  glVertex2i(width,0);  
        glTexCoord2f(1.0f, 0.0f);  glVertex2i(width,height);  
        glTexCoord2f(0.0f, 0.0f);  glVertex2i(0,height);
        glBindTexture(GL_TEXTURE_2D, 0);
        glBindFramebuffer(GL_FRAMEBUFFER, 0);

    However, it's not giving me the expected results, and this is driving me crazy.
    Should I disable GL_BLEND before applying the filter? Case not, which function to use?
    Should I clear my texture before using a shader on it? <-- Never understood this

  9.  The first image shows one circle overlapping another. They were drawn in a texture, with fbo, and blended with



    The second one shows the same stuff, but one circle is on textureA, and the other one on textureB (both handled by a fbo). Each texture was drawn on the screen, calling

    glBindTexture(GL_TEXTURE_2D, textureA);
    glBindTexture(GL_TEXTURE_2D, textureB);


    My question is: why the blending differs? How can I fix it?


  10.  Imagine 3 different balls, each one stored on three different textures. There is no background, so I can draw and overlay (on the front buffer) all of them.
    The problem is: how can I make this draw on a fourth texture, keeping the NO background?

    I'm dealing with multiple layers and want to save all of them in a single png file. Saving what's in the GL_COLOR_ATTACHMENT0 buffer won't work great, because it'll only save what's being seen. Instead, there is a need of saving huge images, which can't be seen (in it's original scale) at one time.


        Layer fourthLayer(0, 0, w, h, 1.0f); // creates a Layer object, which contains a fbo and a texture
        glBindFramebuffer(GL_FRAMEBUFFER, fourthLayer.fbo); // selects the fourth layer's fbo
        render(layers, n);                                 // draw all the three textures
        glBindFramebuffer(GL_FRAMEBUFFER, 0);
        std::vector<unsigned char> pixels(4 * w * h);
        glBindTexture(GL_TEXTURE_2D, fourthLayer.texId); // selects the fourth layer's texture, so I can read it's bytes
        glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0]); 
        glBindTexture(GL_TEXTURE_2D, 0);
        lodepng::encode(filename.append(".png").data(), pixels, w, h); // save



  11. I'm trying to have a copy of my dozens of variables struct inside it, because it'll only be used in that header file. There will be no reason why my main file should know about this copy's existance.
    Using the above struct as an example, should be a funcion named spin(wheel w), which is called millions of times. All I need, for a faster performance, is to copy the struct once, right after it's creation, and not on every spin call.

  12. You can clear a bound FBO texture by using glClearBuffer: http://www.opengl.org/sdk/docs/man3/xhtml/glClearBuffer.xml


    This is available with OpenGL 3.3 or higher, and for best compatibility I'd advise that you stop using the "EXT" versions of the FBO calls and tokens and start using the core GL equivalent.


    Another option is to store the values you wish to clear to in a PBO, and glTexSubImage from the PBO.  That won't involve any FBO changes, will work with downlevel GL, and - since the PBO can be static - should do the transfer entirely on the GPU.

    Thank you! It worked smoothly! By the way, what's wrong with the 'EXT'? (I'm new on FBO's).



    You need to use Ping-Pong texturing. Check out this article which presents an "n" pass post-processing method with FBOs: Tutorial - Post Processing

    Thanks for the further reading.

  13. struct wheel
           wheel *copy;
                  // variables assignment
                  copy = (wheel *)malloc(sizeof(wheel));
                  *copy = *this;
           // variables...

    Is this a reasonable code? Will it behavior nice for my purpose of having a struct's copy that way?


  14. I have a FBO holding a texture, and to that texture I need to apply a post-processing filter, which is done via GLSL.
        So, the way I found to do so:

        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboDst); //fboDst has an empty texture (newTex)
        // ... draw fboSrc texture (oldTex)
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
        copyImage(&fboDst, &fboSrc); // Replace oldTex by newTex via glBlitFramebufferEXT


    Ok. At this point, fboSrc contains my wanted filtered texture. But what if I try to filter it again? Now fboDst isn't clear anymore.
    So I ask you: how to fully clear it, including the alpha channel, without having to recreate everything?

    PS: Have tried glClearColor(1, 1, 1, 0) + glClear(GL_COLOR_BUFFER_BIT) but it seems to screw up my scene.

  15. Edit: The topic can be deleted, sorry.

    I'm trying to pass simple functions to a specific vector and after using them with their indexes. I'm doing good when compiling my code in Dev-C++.

    #include <vector>
    #include <iostream>

    using namespace std;

    typedef int (*funcs)(int, int);
    vector<funcs> functions;

    int sum(int a, int b){return a + b;}
    int sub(int a, int b){return a - b;}

    int main()

    cout << functions[0](5, 4) << endl;
    cout << functions[1](5, 4) << endl;

    return 0;

    The output shows as 9 and 1, for this case.

    However, the same code compiled in VC++ 2008 gives me an Access violation reading location while trying to acess the functions by the vector.
    Should I link or include something to avoid this from occurring?

  16. If you want a solid shape you have to render one face per side (if its infinitly flat then 2 quads are enough).

    I achieved my purpose by using shaders, with a solution that can be found in this very site. Though, your way seems interesting, and I'll study it when I do not want to use shaders...
    However, there is something new and ugly in my project.

    In the following scene, the polygons are drawn in x, y and z bettwen -1 and 1. The light source is at (0, 0, -5). And everthing seems ok.


    But when I rotate my camera...


    ... these black squares appears. They are the ambient light of my scene (0.0, 0.0, 0.0, 1.0). The wierd is that if my light goes to the center (0, 0, 0), these squares (just the ugly ones) remains exactly the same, when they should move along with the light. It seems that the iluminated fractions of the objects rotates as I rotate my camera...
    This can better be seen if I decrease my GL_SPOT_CUTOFF to 30.0f, e.f. That small radius of light moves when I rotate along the x or y axis.

    So, I want them to disapear or to be smooth, at least. Any ideas?

  17. Hello you all, since last week I'm having some trouble while managing lights.

    Imagine a 3D scene with lots of cubes disposed in the middle of the world(0, 0, 0), and a point light source comming from (0, 0, -10). Without taking into account the shadows and so, the (0,0,-1) face of all the cubes should be lit, while the (0, 0, 1) face should not.
    When the light reaches the center, just some faces of the cubes should be lit (the ones that are in the direction of the light).
    Ok, this works perfect when working with glutSolidCube(x), because there is something (not just the normals) in this function that makes what I want to know.
    But, if I create my own polygons and specifies their normals, this effect doesn't work.
    E.g, I can draw a single square in the center of the scene with the normal (0, 0, -1). When the light is located in a z less than 0, that face of the square are lit. But when it's in a z higher than 0, the other face should be lit, but it's not.

    So, it's not just the normals that should be calculated. There is something more in the glutSolidSHAPE that deals good with lights.
    I hope you understand my doubt, since this is my first topic and my english is not that good.

    Thank you!
  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!