Sign in to follow this  

OpenGL Texture loader?

This topic is 3404 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was wondering what is the most simple texture loader to implement/use? On a side note I was wondering how come OpenGL doesn't come with a standard texture loader?

Share this post


Link to post
Share on other sites
I like DevIL.

Khronos maintains OpenGL and a few other open spec solutions.
GL itself is an API for dealing with the GPU. It doesn't bother with file formats.
Also, there are so many file loaders that it's not worth making another one by Khronos.

Share this post


Link to post
Share on other sites
Besides glTexImage2D and glTexSubImage2D are designed to be fun for programmers to figure out, with their random non-sensical error messages and twisted reasons for failing... Who said Khronos don't have a sense of humour!

Share this post


Link to post
Share on other sites
Well by simple I mean simple to install/use. Devil doesn't have enough documentations for me to get started with it.

edit: Well Opengl is a graphic library so I was just wondering why a graphics library doesn't at least come with a standard loader...

Share this post


Link to post
Share on other sites
Quote:
Original post by Shadowwoelf
edit: Well Opengl is a graphic library so I was just wondering why a graphics library doesn't at least come with a standard loader...


They could have added it to GLU but like I said, there are so many other libraries that the cost of paying people to create it and maintain is a big waste.
If it was available, most companies would not even use it.

Think of GL as a stand alone library for only talking to your GPU.

Share this post


Link to post
Share on other sites
The best texture loader that I've seen so far is NeHe's IPicture code (Win32 dependent).

Basically he has a single function that will load a wide variety of formats and even images from the web. It supports transparency as well. It's definitely worth taking a look at; I used it all the time over other gfx libs due to how simple it is. Assuming you are developing for the Win32 platform only, it might be your best bet for now.

Share this post


Link to post
Share on other sites
What are you using? SDL, Win32? OSX? A bit more info is really needed.

If you use SDL, SDL will load many image formats and you can just dump that data into GL. If you are learning OpenGL then get the "Beginning OpenGL game Programming book" they cover .bmp and .tga files and really are simple to load once you work through the code.

Share this post


Link to post
Share on other sites
DevIL is officially driving me crazy. I cannot figure out how to get it to run.

I followed the websites instructions to install and I "think" I did everything right. (Only thing that I couldn't do was add the debug.lib since it wasn't in the zip file)

Then I used this to try and somehow make a patch work of whats going on. Wiki example

And I get 11 linking errors.


Linking...
GameState.obj : error LNK2019: unresolved external symbol __imp__ilDeleteImages@8 referenced in function "public: __thiscall WORLD_STATE::WORLD_STATE(void)" (??0WORLD_STATE@@QAE@XZ)
GameState.obj : error LNK2019: unresolved external symbol __imp__ilGetInteger@4 referenced in function "public: __thiscall WORLD_STATE::WORLD_STATE(void)" (??0WORLD_STATE@@QAE@XZ)
GameState.obj : error LNK2019: unresolved external symbol __imp__ilGetData@0 referenced in function "public: __thiscall WORLD_STATE::WORLD_STATE(void)" (??0WORLD_STATE@@QAE@XZ)
GameState.obj : error LNK2019: unresolved external symbol __imp__ilConvertImage@8 referenced in function "public: __thiscall WORLD_STATE::WORLD_STATE(void)" (??0WORLD_STATE@@QAE@XZ)
GameState.obj : error LNK2019: unresolved external symbol __imp__ilLoadImage@4 referenced in function "public: __thiscall WORLD_STATE::WORLD_STATE(void)" (??0WORLD_STATE@@QAE@XZ)
GameState.obj : error LNK2019: unresolved external symbol __imp__ilBindImage@4 referenced in function "public: __thiscall WORLD_STATE::WORLD_STATE(void)" (??0WORLD_STATE@@QAE@XZ)
GameState.obj : error LNK2019: unresolved external symbol __imp__ilGenImages@8 referenced in function "public: __thiscall WORLD_STATE::WORLD_STATE(void)" (??0WORLD_STATE@@QAE@XZ)
GameState.obj : error LNK2019: unresolved external symbol __imp__ilInit@0 referenced in function "public: __thiscall WORLD_STATE::WORLD_STATE(void)" (??0WORLD_STATE@@QAE@XZ)
GameState.obj : error LNK2019: unresolved external symbol __imp___CrtDbgReportW referenced in function "public: __thiscall std::_Vector_const_iterator<class baseGameState *,class std::allocator<class baseGameState *> >::_Vector_const_iterator<class baseGameState *,class std::allocator<class baseGameState *> >(class baseGameState * *,class std::_Container_base_secure const *)" (??0?$_Vector_const_iterator@PAVbaseGameState@@V?$allocator@PAVbaseGameState@@@std@@@std@@QAE@PAPAVbaseGameState@@PBV_Container_base_secure@1@@Z)
Lesson33.obj : error LNK2001: unresolved external symbol __imp___CrtDbgReportW
.\Debug/Lesson33.exe : fatal error LNK1120: 9 unresolved externals
Build log was saved at "file://d:\Projects\Lesson33\Debug\BuildLog.htm"
Lesson33 - 11 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



Headers

#include <windows.h> // Header File For Windows
#include <stdio.h> // Header File For Standard Input/Output
#include <IL/il.h>
#include <gl\gl.h> // Header File For The OpenGL32 Library
#include <gl\glu.h> // Header File For The GLu32 Library
#include "texture.h" // Header File Containing Our Texture Structure ( NEW )
#include "GameState.h"
#include "globalvariables.h"
#include <vector>
#include <string>




Actually using the library

WORLD_STATE::WORLD_STATE(){
ilInit();
ilGenImages(1, &texid);
ilBindImage(texid);
success = ilLoadImage("town01_a.tga");
if (success)
{
success = ilConvertImage(IL_RGB, IL_UNSIGNED_BYTE);
if (!success)
{
/* Error occured */
done=true;
}
glGenTextures(1, &#8465;);
glBindTexture(GL_TEXTURE_2D, image);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, ilGetInteger(IL_IMAGE_BPP), ilGetInteger(IL_IMAGE_WIDTH),
ilGetInteger(IL_IMAGE_HEIGHT), 0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE,
ilGetData());
ilDeleteImages(1, &texid);
}
}



These three variables are declared private

ILuint texid;
ILboolean success;
GLuint image;

On a side note Wiki example does not actually bind any texture to the quad being drawn which is odd.

So what am I doing wrong?

Share this post


Link to post
Share on other sites

glGenTextures(1, &#8465;);



What are you doing there? You should supply a GLuint variable for this.

glGenTextures(1, &texID);
glBindTexture(GL_TEXTURE_2D, texID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, ilGetInteger(IL_IMAGE_BPP), ilGetInteger(IL_IMAGE_WIDTH),
ilGetInteger(IL_IMAGE_HEIGHT), 0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE,
ilGetData());
ilDeleteImages(1, &texid);

Share this post


Link to post
Share on other sites
That was odd I was actually using & image(for some reason gamedev is changing &_image to a random thingy). And it Still wont compile.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Similar Content

    • By xhcao
      Does sync be needed to read texture content after access texture image in compute shader?
      My simple code is as below,
      glUseProgram(program.get());
      glBindImageTexture(0, texture[0], 0, GL_FALSE, 3, GL_READ_ONLY, GL_R32UI);
      glBindImageTexture(1, texture[1], 0, GL_FALSE, 4, GL_WRITE_ONLY, GL_R32UI);
      glDispatchCompute(1, 1, 1);
      // Does sync be needed here?
      glUseProgram(0);
      glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer);
      glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                                     GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, texture[1], 0);
      glReadPixels(0, 0, kWidth, kHeight, GL_RED_INTEGER, GL_UNSIGNED_INT, outputValues);
       
      Compute shader is very simple, imageLoad content from texture[0], and imageStore content to texture[1]. Does need to sync after dispatchCompute?
    • By Jonathan2006
      My question: is it possible to transform multiple angular velocities so that they can be reinserted as one? My research is below:
      // This works quat quaternion1 = GEQuaternionFromAngleRadians(angleRadiansVector1); quat quaternion2 = GEMultiplyQuaternions(quaternion1, GEQuaternionFromAngleRadians(angleRadiansVector2)); quat quaternion3 = GEMultiplyQuaternions(quaternion2, GEQuaternionFromAngleRadians(angleRadiansVector3)); glMultMatrixf(GEMat4FromQuaternion(quaternion3).array); // The first two work fine but not the third. Why? quat quaternion1 = GEQuaternionFromAngleRadians(angleRadiansVector1); vec3 vector1 = GETransformQuaternionAndVector(quaternion1, angularVelocity1); quat quaternion2 = GEQuaternionFromAngleRadians(angleRadiansVector2); vec3 vector2 = GETransformQuaternionAndVector(quaternion2, angularVelocity2); // This doesn't work //quat quaternion3 = GEQuaternionFromAngleRadians(angleRadiansVector3); //vec3 vector3 = GETransformQuaternionAndVector(quaternion3, angularVelocity3); vec3 angleVelocity = GEAddVectors(vector1, vector2); // Does not work: vec3 angleVelocity = GEAddVectors(vector1, GEAddVectors(vector2, vector3)); static vec3 angleRadiansVector; vec3 angularAcceleration = GESetVector(0.0, 0.0, 0.0); // Sending it through one angular velocity later in my motion engine angleVelocity = GEAddVectors(angleVelocity, GEMultiplyVectorAndScalar(angularAcceleration, timeStep)); angleRadiansVector = GEAddVectors(angleRadiansVector, GEMultiplyVectorAndScalar(angleVelocity, timeStep)); glMultMatrixf(GEMat4FromEulerAngle(angleRadiansVector).array); Also how do I combine multiple angularAcceleration variables? Is there an easier way to transform the angular values?
    • By dpadam450
      I have this code below in both my vertex and fragment shader, however when I request glGetUniformLocation("Lights[0].diffuse") or "Lights[0].attenuation", it returns -1. It will only give me a valid uniform location if I actually use the diffuse/attenuation variables in the VERTEX shader. Because I use position in the vertex shader, it always returns a valid uniform location. I've read that I can share uniforms across both vertex and fragment, but I'm confused what this is even compiling to if this is the case.
       
      #define NUM_LIGHTS 2
      struct Light
      {
          vec3 position;
          vec3 diffuse;
          float attenuation;
      };
      uniform Light Lights[NUM_LIGHTS];
       
       
    • By pr033r
      Hello,
      I have a Bachelor project on topic "Implenet 3D Boid's algorithm in OpenGL". All OpenGL issues works fine for me, all rendering etc. But when I started implement the boid's algorithm it was getting worse and worse. I read article (http://natureofcode.com/book/chapter-6-autonomous-agents/) inspirate from another code (here: https://github.com/jyanar/Boids/tree/master/src) but it still doesn't work like in tutorials and videos. For example the main problem: when I apply Cohesion (one of three main laws of boids) it makes some "cycling knot". Second, when some flock touch to another it scary change the coordination or respawn in origin (x: 0, y:0. z:0). Just some streng things. 
      I followed many tutorials, change a try everything but it isn't so smooth, without lags like in another videos. I really need your help. 
      My code (optimalizing branch): https://github.com/pr033r/BachelorProject/tree/Optimalizing
      Exe file (if you want to look) and models folder (for those who will download the sources):
      http://leteckaposta.cz/367190436
      Thanks for any help...

    • By Andrija
      I am currently trying to implement shadow mapping into my project , but although i can render my depth map to the screen and it looks okay , when i sample it with shadowCoords there is no shadow.
      Here is my light space matrix calculation
      mat4x4 lightViewMatrix; vec3 sun_pos = {SUN_OFFSET * the_sun->direction[0], SUN_OFFSET * the_sun->direction[1], SUN_OFFSET * the_sun->direction[2]}; mat4x4_look_at(lightViewMatrix,sun_pos,player->pos,up); mat4x4_mul(lightSpaceMatrix,lightProjMatrix,lightViewMatrix); I will tweak the values for the size and frustum of the shadow map, but for now i just want to draw shadows around the player position
      the_sun->direction is a normalized vector so i multiply it by a constant to get the position.
      player->pos is the camera position in world space
      the light projection matrix is calculated like this:
      mat4x4_ortho(lightProjMatrix,-SHADOW_FAR,SHADOW_FAR,-SHADOW_FAR,SHADOW_FAR,NEAR,SHADOW_FAR); Shadow vertex shader:
      uniform mat4 light_space_matrix; void main() { gl_Position = light_space_matrix * transfMatrix * vec4(position, 1.0f); } Shadow fragment shader:
      out float fragDepth; void main() { fragDepth = gl_FragCoord.z; } I am using deferred rendering so i have all my world positions in the g_positions buffer
      My shadow calculation in the deferred fragment shader:
      float get_shadow_fac(vec4 light_space_pos) { vec3 shadow_coords = light_space_pos.xyz / light_space_pos.w; shadow_coords = shadow_coords * 0.5 + 0.5; float closest_depth = texture(shadow_map, shadow_coords.xy).r; float current_depth = shadow_coords.z; float shadow_fac = 1.0; if(closest_depth < current_depth) shadow_fac = 0.5; return shadow_fac; } I call the function like this:
      get_shadow_fac(light_space_matrix * vec4(position,1.0)); Where position is the value i got from sampling the g_position buffer
      Here is my depth texture (i know it will produce low quality shadows but i just want to get it working for now):
      sorry because of the compression , the black smudges are trees ... https://i.stack.imgur.com/T43aK.jpg
      EDIT: Depth texture attachment:
      glTexImage2D(GL_TEXTURE_2D, 0,GL_DEPTH_COMPONENT24,fbo->width,fbo->height,0,GL_DEPTH_COMPONENT,GL_FLOAT,NULL); 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_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, fbo->depthTexture, 0);
  • Popular Now