#define fails! Why?
I am trying to set up a #define so that I can setup arrays according to the value given by #define. But it fails to compile.
This is what I have
#define MAPS 2;
GLuint texture[MAPS];
When I change it to "GLuint texture[2];" it compiles. I am having the same problems with for loops and what not. Why is this happeing? Also global integers are failing too...
Any help would be appreciated!
PS: What I am trying to do is to set up a function that will allow me to load a number of texture maps according the value of MAPS.
Thanks!
John William Blair
Thanks!John William Blair "The path of the righteous man is beset on all sides by the inequities of the selfish and the tyranny of evil men. Blessed is he who, in the name of charity and good will, shepherds the weak through the valley of the darkness. For he is truly his brother's keeper and the finder of lost children. And I will strike down upon thee with great vengeance and furious anger those who attempt to poison and destroy my brothers. And you will know my name is the Lord when I lay my vengeance upon thee."
http://members.home.com/chucklez/wtc/index.html
http://members.home.com/chucklez/wtc/index.html
It should be:
Ditch the semicolon. "2;" was being inserted where MAPS was instead of "2".
"Finger to spiritual emptiness underlying everything." -- How a C manual referred to a "pointer to void." --Things People Said
http://www.gdarchive.net/druidgames/
#define MAPS 2
Ditch the semicolon. "2;" was being inserted where MAPS was instead of "2".
"Finger to spiritual emptiness underlying everything." -- How a C manual referred to a "pointer to void." --Things People Said
http://www.gdarchive.net/druidgames/
Also, I suggest using a Linked List instead of an Array to store textures .
"Finger to spiritual emptiness underlying everything." -- How a C manual referred to a "pointer to void." --Things People Said
http://www.gdarchive.net/druidgames/
"Finger to spiritual emptiness underlying everything." -- How a C manual referred to a "pointer to void." --Things People Said
http://www.gdarchive.net/druidgames/
quote: Original post by Null and Void
Also, I suggest using a Linked List instead of an Array to store textures .
Why? you typically have non-linear access to your textures. Linked lists would be slow.
That did it! Thanks! It has been a while since I have been programming in C++.
Thanks!
John William Blair
Thanks!
John William Blair
Thanks!John William Blair "The path of the righteous man is beset on all sides by the inequities of the selfish and the tyranny of evil men. Blessed is he who, in the name of charity and good will, shepherds the weak through the valley of the darkness. For he is truly his brother's keeper and the finder of lost children. And I will strike down upon thee with great vengeance and furious anger those who attempt to poison and destroy my brothers. And you will know my name is the Lord when I lay my vengeance upon thee."
http://members.home.com/chucklez/wtc/index.html
http://members.home.com/chucklez/wtc/index.html
quote: Original post by sjelkjdOriginal post by Null and Void
Also, I suggest using a Linked List instead of an Array to store textures .
Why? you typically have non-linear access to your textures. Linked lists would be slow.
Actually, you shouldn''t be able to see the small difference between a linked list and an Array. But actually, a Linked List would be pretty much the same speed.
Cyberdrek
Headhunter Soft
A division of DLC Multimedia
[Cyberdrek | ]
The way I set it up, I load the textures in to the linked list, and each object has a pointer to the texture that it is using. After all of the objects that are to be rendered are determined, I quicksort them (so that the least amount of state changes are required) and then render them.
It is very fast, and I doubt there is more than a millisecond lost of speed per frame. How do you think professional games store textures? The certainly don''t do it with an array.
"Finger to spiritual emptiness underlying everything." -- How a C manual referred to a "pointer to void." --Things People Said
http://www.gdarchive.net/druidgames/
It is very fast, and I doubt there is more than a millisecond lost of speed per frame. How do you think professional games store textures? The certainly don''t do it with an array.
"Finger to spiritual emptiness underlying everything." -- How a C manual referred to a "pointer to void." --Things People Said
http://www.gdarchive.net/druidgames/
Can I see the code that you are using to load the textures?
Thanks!
John William Blair
Thanks!
John William Blair
Thanks!John William Blair "The path of the righteous man is beset on all sides by the inequities of the selfish and the tyranny of evil men. Blessed is he who, in the name of charity and good will, shepherds the weak through the valley of the darkness. For he is truly his brother's keeper and the finder of lost children. And I will strike down upon thee with great vengeance and furious anger those who attempt to poison and destroy my brothers. And you will know my name is the Lord when I lay my vengeance upon thee."
http://members.home.com/chucklez/wtc/index.html
http://members.home.com/chucklez/wtc/index.html
This doesn't include my other files that are needed to actually use this though (I have a ton of .cpp files in my project, many thousands of lines of code).
"Finger to spiritual emptiness underlying everything." -- How a C manual referred to a "pointer to void." --Things People Said
http://www.gdarchive.net/druidgames/
Edited by - Null and Void on March 15, 2001 11:42:09 PM
#include "RILib/win/global.h"LinkedList <node <TexImage> > Images;node <TexImage> *CacheImage(char *filename) { node <TexImage> *nimg = TextureExists(filename); if(nimg!=NULL) { return (nimg); } else { nimg = Images.AddNode(); nimg->data.path = new char[strlen(filename)+1]; if(LoadTGA(&nimg->data,filename)) { strcpy(nimg->data.path,filename); return (nimg); } else { return NULL; } }}node <TexImage> *CacheUniqueImage(char *filename) { node <TexImage> *nimg = Images.AddNode(); nimg->data.path = new char[strlen(filename)+1]; if(LoadTGA(&nimg->data,filename)) { strcpy(nimg->data.path,filename); return (nimg); } else { return NULL; }}bool LoadTGA(TexImage *texture, char *filename) { GLubyte TGAheader[12] = {0,0,2,0,0,0,0,0,0,0,0,0}; GLubyte TGAcompare[12]; GLubyte header[6]; GLuint bytesPerPixel; GLuint imageSize; GLuint temp; GLuint type=GL_RGBA; FILE *file = fopen(filename,"rb"); if(file==NULL || fread(TGAcompare,1,sizeof(TGAcompare),file)!=sizeof(TGAcompare) || fread(header,1,sizeof(header),file)!=sizeof(header)) { if(file==NULL) { return false; } else { fclose(file); return false; } } texture->width = header[1] * 256 + header[0]; texture->height = header[3] * 256 + header[2]; if(texture->width<=0 || texture->height<=0 || (header[4]!=24 && header[4]!=32)) { fclose(file); return false; } texture->bpp = header[4]; bytesPerPixel = texture->bpp/8; imageSize = texture->width*texture->height*bytesPerPixel; texture->imageData = (GLubyte *) malloc(imageSize); if(texture->imageData==NULL || fread(texture->imageData, 1, imageSize, file)!=imageSize) { if(texture->imageData!=NULL) free(texture->imageData); fclose(file); return false; } for(GLuint i=0; i<int(imageSize); i+=bytesPerPixel) { temp = texture->imageData[i]; texture->imageData[i] = texture->imageData[i+2]; texture->imageData[i+2] = temp; } fclose(file); glGenTextures(1,&texture[0].texID); glBindTexture(GL_TEXTURE_2D, texture[0].texID); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); if(texture[0].bpp==24) { type = GL_RGB; } glTexImage2D(GL_TEXTURE_2D, 0, type, texture[0].width, texture[0].height, 0, type, GL_UNSIGNED_BYTE, texture[0].imageData); return true;}unsigned short AddReference(node <TexImage> *nimg) { nimg->data.refs++; return nimg->data.refs;}unsigned short DeReference(node <TexImage> *nimg) { nimg->data.refs--; if(nimg->data.refs==0) { delete [] nimg->data.path; free(nimg->data.imageData); glDeleteTextures(1,&nimg->data.texID); Images.DeleteNode(nimg); return 0; } else { return nimg->data.refs; }}node <TexImage> *TextureExists(char *path) { node <TexImage> *current = Images.head; while(current!=NULL) { if(strcmp(path,current->data.path)==0) { return current; } current = current->child; } return NULL;}
"Finger to spiritual emptiness underlying everything." -- How a C manual referred to a "pointer to void." --Things People Said
http://www.gdarchive.net/druidgames/
Edited by - Null and Void on March 15, 2001 11:42:09 PM
Also, I have a couple of notes I forgot to mention. I stole the TGA loading code from Nehe, and all of the prototypes (externs) are in global.h (which is fairly large). The linked list class is in framework.cpp (it is huge I couldn''t post it here without feeling bad about wasting the server''s hard drive space ).
"Finger to spiritual emptiness underlying everything." -- How a C manual referred to a "pointer to void." --Things People Said
http://www.gdarchive.net/druidgames/
"Finger to spiritual emptiness underlying everything." -- How a C manual referred to a "pointer to void." --Things People Said
http://www.gdarchive.net/druidgames/
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement