Results 1 to 6 of 6

Thread: Png image rendering slower in my OGL App

  1. #1
    Senior Member Regular Contributor
    Join Date
    Apr 2009
    Posts
    171

    Png image rendering slower in my OGL App

    I know Not posting much of code just part which i think ia an error
    here my request
    please create file as they are below
    test them with valid png file tile.png
    and
    answer me to
    1. why rendering is too much slow
    2. how i feel them with colors

    thanks in advance(i m beginner dont take that in a big fun)
    i hope you not take hard work in fun(huh just pChannel is replaced which is not hat hard)
    thats it




    makefile
    Code :
    LIB = -I/usr/lib
    INC = -I/usr/include
    LINK = -lglut -lGL -lpng
    OBJ = main.o png.o
    COMP = gcc
    pngs:main.o png.o
    	$(COMP) -o 1pntes $(OBJ) $(LIB) $(INC) $(LINK)
    main.cpp
    Code :
    #include <stdlib.h> 
    #include <stdio.h>
    #include <GL/glut.h>
    #define Width	800
    #define Height	600
    unsigned char *loadpng(const char *filename);
    GLuint tex;
    GLfloat theta = 0.0f;
    void LoadTexture()
    {unsigned char *data;
    glGenTextures(0,&amp;tex);
    glBindTexture(GL_TEXTURE_2D,tex);
    data = loadpng("tile.png");
     
       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
     
       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
    		   GL_LINEAR_MIPMAP_NEAREST);
       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    }
    void idle()
    {
     
    // theta +=1.0f;
    glutPostRedisplay();
     
    }
    void Rend()
    {
    glClearColor(0.0f,0.0f,0.0f,0.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glEnable(GL_TEXTURE_2D);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
     
    glPushMatrix();
    glBindTexture(GL_TEXTURE_2D,tex);
     
    glBegin(GL_QUADS);
    glTexCoord2f(0.0f,0.0f);glVertex2f(-1.0f,1.0f);
    glTexCoord2f(-1.0f,0.0f);glVertex2f(1.0f,1.0f);
    glTexCoord2f(-1.0f,-1.0f);glVertex2f(1.0f,-1.0f);
    glTexCoord2f(0.0f,-1.0f);glVertex2f(-1.0f,-1.0f);
    glEnd();
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    glutSwapBuffers();
    }
    void Reshape(int w,int h)
    {
    GLfloat rat = (GLfloat)w/(GLfloat)h;
    if(h==0)h=1;
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(30.0f,rat,1.0f,100.0f);
    glMatrixMode(GL_MODELVIEW);
    glViewport(0,0,w,h);
    }
     
    int main(int argc,char *argv[])
    {
    glutInit(&amp;argc,argv);
     
    glutInitDisplayMode(GLUT_RGBA |GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowSize(Width,Height);
    glutCreateWindow("Png test");
    LoadTexture();
     
     
    glutDisplayFunc(Rend);
    glutReshapeFunc(Reshape);
    glutIdleFunc(idle);
    glutMainLoop();
    }
    png.cpp
    Code :
    #include <stdlib.h> 
    #include <stdio.h>
    #include <png.h>
    #include <GL/glu.h>
    unsigned char *loadpng(const char *filename)
    {
    png_uint_32 width,height;int color_type,bit_depth;
     
    png_structp png_ptr;
    png_infop pinfo_ptr;
    unsigned char sign[8];
    FILE *pngfile;
    printf("Png test\n");
    if(!(pngfile = fopen("tile.png","rb")))
    {
    fprintf(stderr,"file not exist\n");
    }
    fprintf(stdout,"checking PNG signatures\n");
     
    fread(sign,1,8,pngfile);
     
    if(!(png_check_sig(sign,8)))
    {fprintf(stderr,"not a valid signature\n");
    }
    else fprintf(stdout,"signature valid\n");
     
    png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,NULL,NULL,NULL);
    pinfo_ptr = png_create_info_struct(png_ptr);
    if(!pinfo_ptr)
    {
    fprintf(stderr,"info poiter not alloc\n");
    png_destroy_read_struct(&amp;png_ptr,NULL,NULL);
    }
    if(setjmp(png_ptr->jmpbuf)){
    png_destroy_read_struct(&amp;png_ptr,NULL,NULL);
    }
    png_init_io(png_ptr,pngfile);
    png_set_sig_bytes(png_ptr,8);
    png_read_info(png_ptr,pinfo_ptr);
     png_get_IHDR(png_ptr, pinfo_ptr, &amp;width, &amp;height, &amp;bit_depth,
          &amp;color_type, NULL, NULL, NULL);
    int *pChannels;
                           unsigned long *pRowbytes;
    unsigned char *image_data;
    png_uint_32  i, rowbytes;
        png_bytep  row_pointers[height];
     
      if (color_type == PNG_COLOR_TYPE_PALETTE)
            png_set_expand(png_ptr);
        if (color_type == PNG_COLOR_TYPE_GRAY &amp;&amp; bit_depth < 8)
            png_set_expand(png_ptr);
        if (png_get_valid(png_ptr, pinfo_ptr, PNG_INFO_tRNS))
            png_set_expand(png_ptr);
        png_read_update_info(png_ptr, pinfo_ptr);
        fprintf(stdout, "before pChannels assignment\n");
    pChannels = (int*)png_get_channels(png_ptr, pinfo_ptr);
    printf("channel per pixel %i\n",pChannels)  ;
    fprintf(stdout, "before pRowbytes assignment\n ");
       rowbytes = png_get_rowbytes(png_ptr, pinfo_ptr);
     
     
      fprintf(stdout, "before image_data assignment\n ");
        if ((image_data = (unsigned char *)malloc(rowbytes*height)) == NULL) {
            png_destroy_read_struct(&amp;png_ptr, &amp;pinfo_ptr, NULL);
            return NULL;
        }
      fprintf(stdout,"before loop\n");
        for (i = 0;  i < height;  ++i)
            row_pointers[i] = image_data + i*rowbytes;
    png_read_image(png_ptr,row_pointers);
    gluBuild2DMipmaps( GL_TEXTURE_2D,
                                  GL_INTENSITY,
                                  width,height,
                                  GL_RGB,
                                  GL_UNSIGNED_BYTE,
                                  image_data );
     
    }
    what thing i add to get colors in my life
    haven't made a game [img]<<GRAEMLIN_URL>>/frown.gif[/img]

  2. #2
    Senior Member Regular Contributor
    Join Date
    Apr 2009
    Posts
    171

    Re: Png image rendering slower in my OGL App

    OH the fault is my own
    GL_INTENSITY->GL_RGBA
    now rendering slower(on moving that window)
    haven't made a game [img]<<GRAEMLIN_URL>>/frown.gif[/img]

  3. #3
    Senior Member Regular Contributor
    Join Date
    Apr 2009
    Posts
    171

    Re: Png image rendering slower in my OGL App

    please reply me if any one had tried my code
    (i am feeling helpless)
    coloring and orienting is done but performance is slower(OpenGL rendering smooth but on moving window. window moves slower)
    is my code have some issue bug
    please reply me
    have any suggestion PM(Private Message) to me
    haven't made a game [img]<<GRAEMLIN_URL>>/frown.gif[/img]

  4. #4
    Senior Member Regular Contributor
    Join Date
    Dec 2008
    Location
    USA
    Posts
    134

    Re: Png image rendering slower in my OGL App

    You're calling:
    Code :
    glGenTextures(0, &amp;tex);

    The first argument should be the number of new textures, in this case 1. I'm not sure if that's the problem, but you should fix it.

  5. #5
    Senior Member Regular Contributor
    Join Date
    Apr 2009
    Posts
    171

    Re: Png image rendering slower in my OGL App

    I think it is issue with my hardware
    please reply if window moves faster by mouse dragging..
    haven't made a game [img]<<GRAEMLIN_URL>>/frown.gif[/img]

  6. #6
    Senior Member Regular Contributor
    Join Date
    Apr 2009
    Posts
    171

    Re: Png image rendering slower in my OGL App

    Is this buged like programme is only run slower in my Suse 11.0 or it not run other then my system??
    I test some in devil example(by fidding roation in Quad. May be there is my fault but someday i will rectify it that i hopes) the motion of window also slow as the code was doing
    haven't made a game [img]<<GRAEMLIN_URL>>/frown.gif[/img]

Similar Threads

  1. GLSL line rendering is slower than fix function.
    By HanWu in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 11-01-2017, 01:37 AM
  2. Rendering an image
    By slungu in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-20-2009, 10:18 AM
  3. Display list slower than direct rendering?
    By surfdabbler in forum OpenGL: Advanced Coding
    Replies: 9
    Last Post: 06-24-2008, 08:28 PM
  4. Particles render slower and slower as app runs...
    By Kiamo in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 01-02-2005, 12:54 AM
  5. render to depth texture rectangle slower than copy tex sub image
    By JelloFish in forum OpenGL: Advanced Coding
    Replies: 11
    Last Post: 10-18-2002, 02:06 PM

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