LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-22-2005, 12:39 AM   #16
kornerr
Member
 
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893

Original Poster
Rep: Reputation: 35

Yahoo!!! It WORKS!!!
I've downloaded and installed NVIDIA-Linux-x86-1.0-7676-pkg1.run.

BTW, figures don't appear until I move the mouse across the window. You were right.

Thanks for help.
 
Old 10-08-2005, 09:13 AM   #17
kornerr
Member
 
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893

Original Poster
Rep: Reputation: 35
How to know OpenGL version?

Thanks.
 
Old 10-08-2005, 11:06 AM   #18
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
glGetString(GL_VERSION);
 
Old 10-08-2005, 11:55 AM   #19
kornerr
Member
 
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893

Original Poster
Rep: Reputation: 35
Thanks, deiussum.
 
Old 10-23-2005, 02:40 AM   #20
kornerr
Member
 
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893

Original Poster
Rep: Reputation: 35
Does SDL have means for creating UI? If not, how to overcome it?

Thanks.
 
Old 11-04-2005, 09:09 AM   #21
kornerr
Member
 
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893

Original Poster
Rep: Reputation: 35
1) SDL_SetColorKey doesn't work with OpenGL (SDL_GL_SwapBuffers).
How to set the transparent color?
2) When I load PNG with "transparent area" (tried to use PNG instead of the above problem with BMP), an image becomes distorted.
How to fix it?

Thanks.

PS: Modified [02.14PM] Sources [62K]:
engine.tar.bz2.doc
(remove ".doc" from filename)
Requires: OpenGL, SDL, Guichan.

Last edited by kornerr; 11-05-2005 at 01:15 AM.
 
Old 11-04-2005, 10:20 AM   #22
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
With OpenGL you usually do transparency by doing alpha blending or alpha test. With blending you can get a nice semi-transparency effect.

If you do a Google search on alpha blending you'll find lots of info, but just as a quick and dirty guide to get it working:
  • First, you'll need an image format that supports an alpha channel. TGA files are great for this. The Gimp works well for drawing in that alpha channel as well. Google that for some tutorials on how to work with alpha channels in The Gimp.
  • Enable blending with glEnable(GL_BLEND);
  • Set the blending function with glBlendFunc(GL_SRC_ALPHA, GL_SRC_ALPHA_MINUS_ONE);
  • Draw your blended stuff last
  • Either draw your blended stuff in proper back to forward order, or disable depth writing before drawing the blended stuff with glDepthMask(false); (Make sure to enable it again with glDepthMask(true) when you draw your solid items again

For a simple alpha test instead (where either a pixel is drawn or not, no blending is done)
  • Same as first point above. Again, TGAs are a great format for alpha channel support
  • Enable alpha test with glEnable(GL_ALPHA_TEST);
  • You might have to play with the alpha function a bit. I use blending more than alpha test, but I think what you want here is: glAlphaFunc(GL_GEQUAL, 0);
 
Old 11-05-2005, 01:14 AM   #23
kornerr
Member
 
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893

Original Poster
Rep: Reputation: 35
Please, see the sources (in engine.cpp).
I can't get it working...

~~~Edit~~~
All I get is: screenshot

Last edited by kornerr; 11-05-2005 at 01:19 AM.
 
Old 11-05-2005, 02:55 AM   #24
kornerr
Member
 
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893

Original Poster
Rep: Reputation: 35
I understood: in glTexImage2D and gluBuild2DMipmaps I used GL_RGB, not GL_RGBA.

I just can't get one thing: I've made glClearColor (0.0f, 0.0f, 0.0f, 1.0f)
But the screen is cleared as glClearColor (0.3f, 0.3f, 0.3f, 1.0f)!
And when I've made glClearColor (1.0f, 1.0f, 1.0f, 1.0f), the screen was cleared as glClearColor (0.7f, 0.7f, 0.7f, 1.0f)!
And it happens because of the loaded PNG! When no PNG loaded glClearColor (0.0f, 0.0f, 0.0f, 1.0f) works! What's it? Is it a case of an image border?

Thanks.
 
Old 11-06-2005, 11:46 AM   #25
kornerr
Member
 
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893

Original Poster
Rep: Reputation: 35
The problem was in Guichan
 
Old 11-06-2005, 04:39 PM   #26
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
Interesting. I've never used Guichan before. Glad you got it figured out.
 
Old 11-19-2005, 05:11 AM   #27
kornerr
Member
 
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893

Original Poster
Rep: Reputation: 35
GL_TEXTURE_WARP_S/T doesn't work with gluBuild2DMipmaps

Code:
void LoadTexture (char *filename, long texture_id, long mag_filter, long min_filter,
                  long wrap_type, bool transparent = false) {
    SDL_Surface *image;
    image = IMG_Load (filename);
    if (image == NULL) {
        cout << "Couldn't load " << filename << ": " << SDL_GetError () << endl;
        return;
    }

    glBindTexture (GL_TEXTURE_2D, texture_name[texture_id]);

    if (transparent) {
        glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, image->w, image->h, 0, GL_RGBA,
                      GL_UNSIGNED_BYTE, image->pixels);
        gluBuild2DMipmaps (GL_TEXTURE_2D, GL_RGBA, image->w, image->h, GL_RGBA,
                           GL_UNSIGNED_BYTE, image->pixels);
    }
    else {
        glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, image->w, image->h, 0, GL_RGB,
                      GL_UNSIGNED_BYTE, image->pixels);
        gluBuild2DMipmaps (GL_TEXTURE_2D, GL_RGB, image->w, image->h, GL_RGB,
                           GL_UNSIGNED_BYTE, image->pixels);
    };

    glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

    GLenum error = glGetError ();
    cout << error << endl;
    //glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT);
    //glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
}
What is wrong here? I don't get any error, so all should work correctly, but it doesn't.
GL_REPEAT doesn't work: a texture is spread all over a polygon, and not textured repeatedly.

Thanks.

Last edited by kornerr; 11-19-2005 at 05:13 AM.
 
Old 11-19-2005, 09:52 AM   #28
kornerr
Member
 
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893

Original Poster
Rep: Reputation: 35
I've commented glTexImage2D, since you've noticed in another (long ago) post that it shouldn't be used with gluBuild2DMipmaps... but nothing has changed. The texture is still spread all over a polygon...
I've looked at NeHe's and... found no gluBuild2DMipmaps with GL_TEXTURE_WRAP_S
Although I've noticed such trick in the 20th lesson:
Code:
glTexCoord2f( 0.0f, 4.0f ); glVertex3f( -1.1f, -1.1f,  0.0f );
and so on
Whell this trick makes the texture repeat 4 times across the polygon. But it doesn't care of a texture's size.

Thaks.
 
Old 11-19-2005, 10:27 AM   #29
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
Right, if your texcoords only ever go from 0-1, you will never get wrapping. (Because 0 is one edge, and 1 is the other edge, everything in between is a fraction of that.)

If you want repeating based on the size of the image, you're going to have to do a little more work. An easy way if you are just displaying a textured quad, is just to set the projection to an ortho projection the size of the window, and set the texcoords to be something like window coordinate/image size.
 
Old 11-19-2005, 10:52 AM   #30
kornerr
Member
 
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893

Original Poster
Rep: Reputation: 35
I have
Code:
void ResizeWindow (int width, int height) {
    if (height == 0)
        height = 1;
    glViewport (0, 0, (GLint)width, (GLint)height);

    glMatrixMode (GL_PROJECTION);
    glLoadIdentity ();
    gluPerspective (90.0f, (float)width / (float)height, 0.00001f, 5.0f);
    glMatrixMode (GL_MODELVIEW);
}
so what should be the formula?

Thanks.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sdl / opengl - cant press up and right atrain Linux - Games 2 03-27-2005 11:29 PM
Question about SDL OpenGL and -lglut doody Programming 2 11-16-2004 04:17 PM
OpenGL and SDL programming with Slackware zsejk Slackware 13 08-03-2004 07:52 PM
Using OpenGL (+SDL) for 2D programs R00ts Programming 4 07-16-2004 12:33 PM
OpenGL lighting with SDL MadCactus Programming 0 09-21-2003 11:52 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration