OpenGL Image Textures
Yes, compression is where the argument is. Why use TGA when libpng is so easy to use? PNG supports alpha and compresses far better than TGA and is lossless too, not to mention cross-platform compatible. I've never had any problems with load time so I've never bothered to compare. I just don't see any arguments in favor of using TGA over PNG.
With TGA or PPM, you can avoid dependency of libpng and have the whole loader at your fingertips. That is a good backdoor any time you find yourself on a platform without libpng, and simplifies the setup while learning (definitely an advantage in CG teaching). Any time a student has an unusual setup, you get strange questions about why they can't fine libjpeg and libpng. They are good, but often require extra work. It is no problem for my own programming, but as a teacher, TGA makes life easier.
There are always other ways to see things, other needs. I don't in any way argue against PNG, sure it is more advanced and theerfore gives better compression, I only say that it may not be the shortest route to that first running version of your first game.
There are always other ways to see things, other needs. I don't in any way argue against PNG, sure it is more advanced and theerfore gives better compression, I only say that it may not be the shortest route to that first running version of your first game.
Fair enough I guess. If I were teaching though, I'd probably teach them how to use libpng first thing

OK, I'll forget TGA for now, and stick with SOIL.
It still won't load. I drag 'libSOIL.a' to the Xcode frameworks group, then type
It gives me error: 'SOIL.h: No such file or directory'. I don't see why?
It still won't load. I drag 'libSOIL.a' to the Xcode frameworks group, then type
Code:
#include "SOIL.h"
It gives me error: 'SOIL.h: No such file or directory'. I don't see why?
~ Bring a Pen ~
ThemsAllTook Wrote:I'd suggest putting it in one of your user-defined search paths and using double quotes instead of angle brackets to include it.
Have you done this yet?
Quote:using double quotes instead of angle brackets to include it.Well, I have. Can't you see that? Or am I overlooking something?
Quote:user-defined search pathsI thought that meant putting it in 'frameworks'?
~ Bring a Pen ~
You can probably just drag soil.h into your project (right next to libSoil.a is logical). That has the added bonus of you being able to refer to the header right there in your project if you need to.
OK cool thanks, but does that mean if I need another of SOIL's files, I need to drag it there too?
***
I am having problems again. I can't decide where to put:
I can't put it after all my #includes, as C can't create variables based on function calls inside functions. If I put it in main() when I draw the plane in drawScene() It won't recognise it, as it's not global. If I put it in drawScene() It doesn't recognise SOIL_load_OGL_texture.
***
I am having problems again. I can't decide where to put:
Code:
GLuint flats_tex = SOIL_load_OGL_texture ("Flat.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 );
if( 0 == flats_tex)
{
printf( "SOIL loading error: '%s'\n", SOIL_last_result() );
}
I can't put it after all my #includes, as C can't create variables based on function calls inside functions. If I put it in main() when I draw the plane in drawScene() It won't recognise it, as it's not global. If I put it in drawScene() It doesn't recognise SOIL_load_OGL_texture.
~ Bring a Pen ~
That's correct. Well, actually, maybe. Xcode might know to look in the same path as you used for SOIL.h now that I think of it. I always drag the ones I need anyway so that I can refer to them, so I don't recall ever testing that...
I am having problems again. I can't decide where to put:
I can't put it after all my #includes, as C can't create variables based on function calls inside functions. If I put it in main() when I draw the plane in drawScene() It won't recognise it, as it's not global. If I put it in drawScene() It doesn't recognise SOIL_load_OGL_texture.
Code:
GLuint flats_tex = SOIL_load_OGL_texture ("Flat.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 );
if( 0 == flats_tex)
{
printf( "SOIL loading error: '%s'\n", SOIL_last_result() );
}
I can't put it after all my #includes, as C can't create variables based on function calls inside functions. If I put it in main() when I draw the plane in drawScene() It won't recognise it, as it's not global. If I put it in drawScene() It doesn't recognise SOIL_load_OGL_texture.
~ Bring a Pen ~
Break the line into two pieces. Define the variable globally:
Then assign it a value in a function somewhere:
Then read AnotherJake's post below for how to fix the other problem I didn't notice,
Code:
GLuint flats_tex
Code:
aFunction()
{
flats_tex = SOIL_load_OGL_texture ("Flat.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 );
if( 0 == flats_tex)
{
printf( "SOIL loading error: '%s'\n", SOIL_last_result() );
}
}
Then read AnotherJake's post below for how to fix the other problem I didn't notice,
... whole bunch of problems here. backslash covered part of it. The trickier issue for you is going to be the part where it doesn't recognize SOIL_load_OGL_texture. That suggests to me that you're still using the lib that came compiled with SOIL. That lib doesn't work on OS X, so you'll have to compile a new one:
In the SOIL folder, where you'll see some test images and a lib and src folder and some others, make a new folder named obj. Then navigate to projects/makefile. In there should be the makefile. You'll need to make a slight modification to it, so open it in TextEdit (or whatever), and modify the line that says:
OBJDIR = obj
so that it says:
OBJDIR = ../../obj
and save it.
Then launch Terminal. In Terminal, type cd, then drag the makefile directory onto Terminal and hit return. To make sure you're in the right directory, if you type ls and return you should get "alternate Makefile.txt makefile". Then type make and return and it'll do some compiling. The new Mac compatible lib should now be in the lib directory.
To actually use SOIL, here's a little GLUT demo for you:
In the SOIL folder, where you'll see some test images and a lib and src folder and some others, make a new folder named obj. Then navigate to projects/makefile. In there should be the makefile. You'll need to make a slight modification to it, so open it in TextEdit (or whatever), and modify the line that says:
OBJDIR = obj
so that it says:
OBJDIR = ../../obj
and save it.
Then launch Terminal. In Terminal, type cd, then drag the makefile directory onto Terminal and hit return. To make sure you're in the right directory, if you type ls and return you should get "alternate Makefile.txt makefile". Then type make and return and it'll do some compiling. The new Mac compatible lib should now be in the lib directory.
To actually use SOIL, here's a little GLUT demo for you:
Code:
#include <stdlib.h>
#include <stdio.h>
#include <GLUT/glut.h>
#include "SOIL.h"
GLuint myTexture;
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glTranslatef(100.0f, 100.0f, 0.0f);
glBindTexture(GL_TEXTURE_2D, myTexture);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex2f(0.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f);
glVertex2f(256.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f);
glVertex2f(256.0f, 256.0f);
glTexCoord2f(0.0f, 1.0f);
glVertex2f(0.0f, 256.0f);
glEnd();
glutSwapBuffers();
}
void reshape(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, width, 0, height);
glMatrixMode(GL_MODELVIEW);
}
void idle(void)
{
glutPostRedisplay();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
glutInitWindowSize(640, 480);
glutCreateWindow("SOIL test");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(idle);
myTexture = SOIL_load_OGL_texture("myImage.png", 0, 1, SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_INVERT_Y);
if (!myTexture)
{
printf("soil failed to load texture\n");
exit(0);
}
glEnable(GL_TEXTURE_2D);
glutMainLoop();
return EXIT_SUCCESS;
}
Nope. I do all you said exactly, but It still doesn't recognise it.
I took a ~2min video, I'll upload it soon.
I took a ~2min video, I'll upload it soon.

~ Bring a Pen ~
Isn't Mikey's problems exactly what I talked about? Adding a small C file for loading a texture sounds a bit easier to me.
This brings me to a related question: When using libraries like libjpeg, libpng and libz, there are several different ways to install and use it.
- Unix-style installation, static link. I would consider this default. I also consider Unix-style installers rather scary.
- Local library copy, static link. Easiest?
- Install as Framework. There are framework versions of both libjpeg and libpng. The framework can be either global or inside the app bundle.
One may say "they all work", and I guess they do, but what do you prefer, and why? Also, what is best for the inexperienced user, what gives the least number of nasty pitfalls?
This brings me to a related question: When using libraries like libjpeg, libpng and libz, there are several different ways to install and use it.
- Unix-style installation, static link. I would consider this default. I also consider Unix-style installers rather scary.
- Local library copy, static link. Easiest?
- Install as Framework. There are framework versions of both libjpeg and libpng. The framework can be either global or inside the app bundle.
One may say "they all work", and I guess they do, but what do you prefer, and why? Also, what is best for the inexperienced user, what gives the least number of nasty pitfalls?
Well, the concept is simple: You have a static library and a header. You drag those two onto your project and call:
GLuint myTexture = SOIL_load_OGL_texture("myImage.png", 0, 1, SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_INVERT_Y);
How exactly that is harder than loading a TGA with your own code I don't know.
I took the time to work out detailed instructions on how to build one of the simplest libraries in the world *and* a simple working GLUT demo, and in return I get a "see I told you so". ...
GLuint myTexture = SOIL_load_OGL_texture("myImage.png", 0, 1, SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_INVERT_Y);
How exactly that is harder than loading a TGA with your own code I don't know.
I took the time to work out detailed instructions on how to build one of the simplest libraries in the world *and* a simple working GLUT demo, and in return I get a "see I told you so". ...
Possibly Related Threads...
Thread: | Author | Replies: | Views: | Last Post | |
[SOLVED]OpenGL edges of textures | mk12 | 2 | 6,456 |
Sep 2, 2010 08:07 PM Last Post: mk12 |
|
Dealing with inverted textures in OpenGL | johncmurphy | 7 | 10,347 |
Jun 15, 2009 08:11 AM Last Post: Skorche |
|
Using textures OpenGL switches to software renderer | bruno | 2 | 5,283 |
Oct 12, 2008 03:06 AM Last Post: bruno |
|
Loading and using textures with alpha in OpenGL with Cocoa | corporatenewt | 4 | 9,389 |
Dec 8, 2007 02:06 PM Last Post: Malarkey |
|
loading textures - cocoa openGL | mDmarco | 20 | 15,888 |
Aug 28, 2007 08:48 PM Last Post: OneSadCookie |