Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

openGL and Textures

Name: Anonymous 2010-11-13 14:52

So /anus/, I've been reading tutorials on openGL and how to render textures to the screen, but whenever i try all i get is a black box
here is my texture loading code

GLuint LoadTexture(const char *filename)
{
    GLuint texture = FALSE;

    /* Create storage space for the texture */
    SDL_Surface *TextureImage[1];

    /* Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit */
    if ( ( TextureImage[0] = IMG_Load(    filename ) ) )
    {
            /* Create The Texture */
            glGenTextures( 1, &texture );
           
            /* Load in texture 1 */
            /* Typical Texture Generation Using Data From The Bitmap */
            glBindTexture( GL_TEXTURE_2D, texture);
           
           
            //create the image
            glTexImage2D(GL_TEXTURE_2D,
                         0,
                         4,                    //alpha enabled
                         TextureImage[0]->w,
                         TextureImage[0]->h,
                         0,
                         GL_RGBA,            //HERP
                         GL_UNSIGNED_BYTE,
                         TextureImage[0]->pixels);

            /* Nearest Filtering */
            glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
            glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
    }

    /* Free up any memory we may have used */
    if ( TextureImage[0] )
        SDL_FreeSurface( TextureImage[0] );

    return texture;
}


and the render code:

glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho (0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 1);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity();

/* Clear The Screen And The Depth Buffer */
glClearColor(1.0f,1.0f,1.0f,0.0f); //white
glClear( GL_COLOR_BUFFER_BIT );

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,anus);
glBegin(GL_QUADS);
    glTexCoord2d(0.0,0.0); glVertex2d(50.0,50.0);
    glTexCoord2d(1.0,0.0); glVertex2d(90.0,50.0);
    glTexCoord2d(1.0,1.0); glVertex2d(90.0,90.0);
    glTexCoord2d(0.0,1.0); glVertex2d(50.0,90.0);
glEnd();


glPushMatrix();
glMatrixMode(GL_PROJECTION);
glPushMatrix();

Name: Anonymous 2010-11-13 15:24

What makes you think anyone here could help you fix it?

Name: Anonymous 2010-11-13 15:32

>>2
because IHBT

Name: Anonymous 2010-11-13 16:12

I dont code OpenGL, but I dont see any code that blits the texture to the surface, if youre using double buffers. And another problem you might have is that you didnt position the camera to point at the texture poly.

Name: Anonymous 2010-11-13 18:13

1. Use glGetError to help find problems.
2. Post a small complete program that shows the problem.

Name: Anonymous 2010-11-13 18:13

I see your problem, you're a faggot. But besides that, how can we help you if you don't post your shaders?

Name: Anonymous 2010-11-13 19:56

>>6
But besides that, how can we help you if you don't post your shaders?
IHBT

Name: Anonymous 2010-11-14 1:36

If the image is loading correctly (and it may pay to check that the size of the image is 2n.

Namely though, your call to glOrtho is completely fucked. See: http://www.opengl.org/sdk/docs/man/xhtml/glOrtho.xml , the camera is on the near plane which isn't a good idea, you aren't clearing the depth buffer and the QUAD you draw is at z-depth 0, so you might not even see it considering the camera is at (0, 0, 0).

Name: Anonymous 2010-11-14 14:43

>>7
Oh please, don't tell me you're going to use the deprecated fixed function rendering pipeline.

Name: Anonymous 2010-11-14 15:11

>>9
wat

Name: Anonymous 2010-11-14 16:44

>>9
>>6
how does i do shaders

Name: Anonymous 2010-11-14 17:05

>>11
go to /3/ and find out what they are and how to use them in a 3D app before ask how they are programmed

Name: Anonymous 2010-11-14 19:07

Name: Anonymous 2010-11-14 19:12

All i wanted to do is simple 2D UI stuff and i end up finding out all my beloved functions are deprecated and i have to do shader stuff now for simple UI

Name: Anonymous 2010-11-14 19:17

All i wanted to do is simple HTML stuff and i end up finding out all my beloved HTML tags are deprecated and i have to do CSS stuff now for simple HTML

Name: Anonymous 2010-11-14 19:19

>>14
If it makes you feel better fixed function might be deprecated but the drivers will make it available forever on the desktop.

You might have less luck with new gadgets and their OpenGL subsets though.

Name: Anonymous 2010-11-14 19:23

>>16
oh, well that's nice. Thank you, i'll slowly switch to shaders later down the road then.

Name: Anonymous 2010-11-14 20:41

>>9
Writing shaders for this shit is retarded. Do you use raw Xlib to write GUIs too?

Name: Anonymous 2010-11-14 21:12

>>18
???? ????????, ???????????? ????????????

Name: Anonymous 2010-11-14 22:02

I find it funny that people go around touting OpenGL 2.x as deprecated when 3.x is only supported by ~40% of users per the Steam hardware survey, and 4.x is supported by maybe two graphics cards total.

Name: Anonymous 2010-11-14 22:39

>>18
You'd know how idiotic that comparison is if you had any experience with either Xlib or OpenGL. It's easier to just use a simple shader than to futz around with the fixed pipeline until it does what you want.

Name: Anonymous 2010-11-14 23:15

>>20
You're confused, possibly from bad influence from DirectX. If you were to say that a version of OpenGL was deprecated, which you shouldn't, it would be OpenGL 1.

Name: Anonymous 2011-02-03 3:06


Don't change these.
Name: Email:
Entire Thread Thread List