1

This is the code I'm using, but its not loading anything: It is supposed to load frog.png onto a window. The image is present is the cwd. The output im getting is a blank screen with nothing on it. Am I missing some functions ?

#include <math.h>
#include <GL/glut.h>
#include<stdio.h>
#include<SOIL.h>

void init(void){

        glClearColor(1.0,1.0,1.0,1.0); 
        glMatrixMode(GL_PROJECTION);
        gluOrtho2D(0.0,300.0,0.0,300.0);
    }


void drawPoints(void){

        glClear(GL_COLOR_BUFFER_BIT);
        glColor3f(1,0.4,0.6);//rgb values

       GLuint tex_2d = SOIL_load_OGL_texture
    (
        "frog.png",
        SOIL_LOAD_AUTO,
        SOIL_CREATE_NEW_ID,
        SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
    );

// check for an error during the load process 
if( 0 == tex_2d )
{
    printf( "SOIL loading error: '%s'\n", SOIL_last_result() );
}
        glFlush();
}

int main(int argc, char **argv){

        glutInit(&argc,argv);
        glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
        glutInitWindowPosition(100,100); 
        glutInitWindowSize(100,100); 
        glutCreateWindow("example");
        init();
        glutDisplayFunc(drawPoints);
        glutMainLoop(); 
}
ana12345
  • 11
  • 1
  • 1
    As a high-level observation, doing file I/O in the drawing function (which can run 100+ times per second, depending on your window environment and hardware) is not optimal. – unwind Mar 24 '20 at 09:21
  • To follow up on the comment by @unwind, you don't need to load the texture more than once anyway. – Some programmer dude Mar 24 '20 at 09:23
  • 1
    It is not enough to load the texture. You have to draw a geometry and to wrap the texture on it. See [How do opengl texture coordinates work?](https://stackoverflow.com/questions/5532595/how-do-opengl-texture-coordinates-work) – Rabbid76 Mar 24 '20 at 14:55

0 Answers0