Results 1 to 6 of 6

Thread: A few small rendering problems

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2011
    Location
    Victoria B.C.
    Posts
    2

    A few small rendering problems

    Hello, I am just starting to program with SDL and OpenGL and I have run into a few problems that I cant figure out.
    (most have my code has been copied from various tutorials)

    -First off, I have a method that draws a basic white square. I set the color to white before I define the verticies, which on its own draws the correct color but when it is with an image, the square becomes the background color(most dominant?) of the last image drawn





    -Second, I am having trouble appliying transparency to an Image. I have tried making the background dirrectly transparent with an image editing program, and also by using a color key but neither seem to work with OpenGL...

    As you can see from the images above neither ship has transparency, but using the same code with just SDL the black background is removed.




    Thanks for the help, sorry if these are really basic problems

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Karachi, Pakistan
    Posts
    810

    Re: A few small rendering problems

    Can u post your fillRect function?
    Regards,
    Mobeen

  3. #3
    Junior Member Newbie
    Join Date
    Apr 2011
    Location
    Victoria B.C.
    Posts
    2

    Re: A few small rendering problems

    Yea no problem, here is the method, it is Contained within the GraphicsFrame class so any variable not declared locally is in the class.

    Seems pretty straight forward, unless I am using the basic GL functions wrong.


    Code :
    void GraphicsFrame::fillRect(int x,int y, int width, int height)
    {
            //Move to offset
    	glTranslatef( x+xOffSet, y+yOffSet, 0 );
     
     
    	//Set color to white
    	glColor4f( 1.0,1.0, 1.0, 1.0 );
     
            //Start quad
    	glBegin( GL_QUADS );
     
    	//Draw square
    	glVertex3f( 0,     0,      0 );
    	glVertex3f( width, 0,      0 );
    	glVertex3f( width, height, 0 );
    	glVertex3f( 0,     height, 0 );
     
    	//End quad
    	glEnd();
     
    	//Reset
    	glLoadIdentity();
    }

    If this doesnt work I can simply recolor and stretch an image of a white square programaticly

  4. #4
    Senior Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Karachi, Pakistan
    Posts
    810

    Re: A few small rendering problems

    Put the glColor4f call inside the glBegin/glEnd pair before the first glVertex call and then tell us if u still see the same behaviour.
    Regards,
    Mobeen

  5. #5
    Newbie OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,789

    Re: A few small rendering problems

    That shouldn't matter because glColor just sets the current colour which subsequent calls to glVertex will pick up and send to the GPU.

    If you want transparency on an image in OpenGL then look at alpha blending or alpha testing.

  6. #6
    Senior Member Regular Contributor
    Join Date
    Oct 2010
    Location
    France
    Posts
    458

    Re: A few small rendering problems

    For your first problem, don't use GL_MODULATE environment color when creating your texture, use GL_REPLACE instead. Or just glColor3f (1,1,1) before drawing a textured object.

Similar Threads

  1. small problems with beam program + ligtht position
    By newsb in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 04-14-2012, 02:16 PM
  2. Two small problems in Appendix D.3
    By awoodland in forum OpenCL
    Replies: 2
    Last Post: 03-09-2011, 06:39 PM
  3. Problems rendering
    By ToddAtWSU in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 10-10-2007, 08:07 AM
  4. MD3 Rendering Problems
    By nukem in forum OpenGL: Advanced Coding
    Replies: 10
    Last Post: 08-27-2003, 08:25 PM
  5. Rendering problems
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 06-01-2000, 11:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean