Jump to content

  • Log In with Google      Sign In   
  • Create Account

Brother Bob

Member Since 26 Nov 2001
Offline Last Active Today, 12:54 AM

#5026998 Alpha Blending

Posted by on 29 January 2013 - 05:47 PM

Your call to glTexImage discards the alpha channel since you only request a texture with three color channels. The third parameter is equivalent to GL_RGB, which means the texture contains a red, a green and a blue channel, but no alpha channel. Use GL_RGBA instead.




#5026191 Wavefront OBJ file reading - Polygons connect incorrectly

Posted by on 27 January 2013 - 03:58 PM

In C++, an index is 0-based which means that the first element of an array has index 0, the second element has index 1, the third element has index 2, and so on. The OBJ file is 1-based, which means that the first vertex has index 1, the second vertex has index 2, the third vertex has index 3, and so on. Therefore, you cannot read an index from the OBJ file and use it directly to reference a C++ array.

 

The indices are what you read from the f-lines. For example, "f 1 2 3" means: the face is made up of three vertices (because there are three values), and the vertices are the vertex with index 1, the vertex with index 2, and the vertex with index 3.




#5026188 What OpenGL Implementation Do Real Games Use?

Posted by on 27 January 2013 - 03:48 PM

The standard <GL/gl.h>.




#5026094 What OpenGL Implementation Do Real Games Use?

Posted by on 27 January 2013 - 10:12 AM

Neither GLUT nor FreeGLUT are OpenGL implementations. They are windowing layers for OpenGL. Mesa3D is a software implementation that provides limited possibilities for hardware acceleration.

 

If you're on Windows, there's pretty much only one sensible option; you use the default implementation that the operating system provides. The benefit with using that implementation is that each hardware manufacturer provides their own hardware driver for it. Just link the standard opengl32.lib that ships with your compiler to use it.




#5026030 Wavefront OBJ file reading - Polygons connect incorrectly

Posted by on 27 January 2013 - 06:20 AM

Looks like you're not converting the vertex indices. The obj-file has 1-based indices but std::vector has 0-based indices.




#5025935 Deleting value stored inside a pointer

Posted by on 26 January 2013 - 08:43 PM





Deleting something doesn't automatically set the pointer to null. You'll need to nullify it yourself.

delete ptr[x];ptr[x] = NULL;
But if you take this approach, then you need to check for NULL every time you access the array.
If you need to litter your code with null-checks, then you have ownership issues that needs to be solved instead. You should not ask yourself if you need to check for null before accessing a pointer, you should ask yourself why the pointer can be deleted in the first place if you still need it.

If you delete the objects you have allocated, but then keep using the objects afterwards, your program is ill-formed. That does not mean that your program must crash or must produce an incorrect result. It may do that, but it doesn't have to. Nevertheless, your program is ill-formed.

I never said I was going to keep using the objects after I delete them. I said I was going to use the pointers and I don't want to delete the pointers, I want to delete what the pointers are pointing to.
The term "delete a pointer" means just that; you delete the object the pointer points to. That is, delete ptr does not delete ptr itself, it delete what ptr points to.


#5025916 Deleting value stored inside a pointer

Posted by on 26 January 2013 - 07:13 PM

If you delete the objects you have allocated, but then keep using the objects afterwards, your program is ill-formed. That does not mean that your program must crash or must produce an incorrect result. It may do that, but it doesn't have to. Nevertheless, your program is ill-formed.




#5025891 Deleting value stored inside a pointer

Posted by on 26 January 2013 - 05:56 PM

You need to call delete for everything you call new for. You call new for ptr[x], for each x in the array, so you need to call delete for ptr[x] as well.
for(int x=0; x<10; ++x) {
    delete ptr[x];
}



#5025881 Delete VBOs at run time?

Posted by on 26 January 2013 - 05:24 PM

Deleting buffers at run time makes the next draw call ends with an access violation.

This one makes me seriously wonder what you're doing.

 

Are you creating and deleting the buffer objects for every frame? That is a very big no-no. What you need to do is create them once and delete them when you're done with them, at the end of the game, or at the end of the level, or whenever you don't need the objects anymore. But don't create and recreate them on a per-frame basis.

 

I can also interpret your question as a serious ownership-problem; you are deleting objects that shouldn't be deleted in the first place because you are still using them. In that case, you should read up on resource ownership and what it means with something owning a resource and controlling when it's being deleted. In no case should a resource be deleted that you either need or have a replacement for (such as a dummy resource that you can use instead of the actual resource isn't available).




#5025153 One way list into glVertexPointer

Posted by on 24 January 2013 - 11:47 AM

OpenGL can only use attributes stored linearly in memory and cannot read non-linear data structures.




#5024071 Tile sheet spriting math ?

Posted by on 21 January 2013 - 05:11 PM

Subtract one from the values you read from the map and then work with zero-based indexing. The math turns out so much cleaner with zero-based indexing.




#5023893 Reading binary file to vbo in OpenGL

Posted by on 21 January 2013 - 08:17 AM

The significant performance issue is going to be the physical disk IO and not which logical method you use. Just don't make some stupid performance test where you don't take the physical disk IO into account and just keeps reading from any of the multiple levels of cache along the way to come to an irrelevant conclusion.




#5023837 Whats wrong with this code?

Posted by on 21 January 2013 - 04:59 AM

Please specify the environment you're using and in what context it is used. This looks like a very limited piece of code. But just looking at the code, I see no reason why the callbacks would matter. The program flow seems to be like this:

  1. Get some button handles
  2. Define an uninitialized variable num
  3. Set button callbaks.
  4. Print the value of num.

There are no callbacks happening before printing in step 4, and thus no chance of printing anything but the uninitialized value from step 2.




#5023455 Compiler error on Counting how many lines there is?

Posted by on 20 January 2013 - 04:52 AM

strtok modifies the string you pass, but you're passing a string literal which cannot be modified. You have to allocate memory for the string, either dynamically or statically.

char string[] = "This is a simple game lets enjoy this\nIt breaks a new era in to games\nwhahahaha zoom in";
int lines = count_lines(string);




#5023177 Text error in C

Posted by on 19 January 2013 - 08:46 AM

You have to allocate memory for the pointer to point to. Look up malloc() and free() on how to allocate memory dynamically.

 

For example:

int length = strlen(text);
char *buf = malloc(length-pos+2); // +1 for null character, +1 for the inserved character, and -pos since we don't have to allocate the part of the string before pos.
sprintf(buf, "%c%s", c, text+pos);
strcpy(text+pos, buf);
free(buf);






PARTNERS