Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 06 Apr 2011
Offline Last Active May 28 2013 09:36 AM

Topics I've Started

3D Terrain Editor [Warcraft 3 Style]

29 August 2012 - 04:01 AM

Hello to all!

I am making a simple 3D Strategy game resembling Starcraft and Warcraft 3. For this game I want to develop a terrain editor. I want my terrain
editor to have the same functionality as the Warcraft III terrain with which I can create terrain like that in the picture below.

Posted Image

This is an example terrain created with the Warcraft III Editor. I did some research and managed to find some information on how the editor works.

The Warcraft III Terrain editor is tile based. Each tile can have its own texture, as well as different height for each of its four points. The are two major tile types. Normal (flat) tiles which are just a plain heightmap, and cliff tiles which are composed of complex geometry.

Before I start building the terrain editor I started thinking about the different aspects of such an editor and found my self with a few questions:

1.) The whole terrain will be represented by a single Vertex Buffer. This buffer will be recreated every time the camera moves and contain only the visible vertices of the terrain. is this possible and will it pull too much strain on the video card? What are other possibilities? Should I use LOD for a 3D strategy game which has a top-down view tilted 45 degrees on the Y axes? (Like the picture)

2.) I will create a single large texture for every terrain type. (Grass, Stone, etc...) and then use alpha maps to blend them together and apply over the terrain then use another texture with multi-texturing to add detail. Is this a good solution? Will I be able to achieve good quality texturing if I build a big texture for the whole terrain? Is it better to create many small textures? Should I devide the terrain into small parts each having its own textures and vertex buffer and then just do a simple check of the position of the camera to remove the non visible parts of the terrain?

3.) How will I be able to achieve square hills like the picture? What I am thinking of using is having a quad of the terrain, which are parts of hills do be subdivided and then displaced using a heighmap texture ( to make the hill look like there are rocks sticking out). Is it better to just create a mesh for a hill (tillable) and then where there's a hill I simply render the mesh ontop? What other possible ways are there?

I think that's all. I hope someone can answer my questions :(

Thank you for your time!

Template class problems

19 August 2012 - 10:16 AM

Hello guys. I am making a memory manager and I have stumbled onto a very weird problem. I am making a new template class like so

namespace CWolf
    template <class T>
    class CWStackAllocator
		    // Constants
			    CW_DEFAULT_SIZE = 100,
			    // Error constants
			    The allocated memory is stored in the form of a double linked list.
			    This structure represents a node in that list.
		    struct CW_ELEMENT
			    T data;
			    CW_ELEMENT *pPrev;
			    CW_ELEMENT *pNext;
			    A marker showing the top of the stack. You can only roll back to a
		    typedef uint32_t Marker;
			    Default constructor.
			    @param stackSize - Optional paramater. It tells the initial stack size.
		    explicit CWStackAllocator(uint32_t stackSize = CW_DEFAULT_SIZE);
			    Default destructor. Frees all of the memory used by the allocator.
			    Called automatically.
		    virtual ~CWStackAllocator();
			    This function allocates a new block of the given size from stack
			    @param size - the size of the chunk which to allocate
		    T* MemAlloc(uint32_t size);
			    Get a marker to the top of the stack
			    @return Marker - top of the stack
		    Marker MemGetMarker();
			    Rolls the stack back to a previous marker
			    @param marker - marker showing where to roll back to
		    void MemFreeToMarker(Marker marker);
			   Clears the entire stack (rolls the stack back to zero).
		    void MemClear();
		    CW_ELEMENT *m_pFirstFree;
		    CW_ELEMENT *m_pFirstUsed;
		    uint32_t m_MaxElements;
		    CW_ELEMENT *m_pMemory;

#include "CWStackAllocator.h"
namespace CWolf
    template<class T>
    CWStackAllocator<T>::CWStackAllocator(uint32_t stackSize) :
	    m_MaxElements(stackSize), m_pFirstUsed(0)
	    // Allocate enough memory for the maximum number of elements
	    char *pMemory = new char[m_MaxElements * sizeof(CW_ELEMENT)];
	    // Handle problems
	    // TODO (hentailoli#) Implement CWException
	    if (pMemory == 0)
	    // Cast the memory to our internal format
	    //m_pMemory = (CW_ELEMENT*) pMemory;
	    m_pMemory = dynamic_cast<CW_ELEMENT*>(pMemory);
	    // Set the free list first pointer
	    m_pFirstFree = m_pMemory;
	    // Clear the memory (is this really needed?)
	    memset(m_pMemory, 0, sizeof(CW_ELEMENT) * m_MaxElements);
	    // Point at first element
	    CW_ELEMENT *pElement = m_pFirstFree;
	    // We don't have a previous element since this is the first one
	    pElement.pPrev = 0;
	    pElement.pNext = pElement + 1;
	    // Set the double linked free list
	    for(uint32_t i = 1; i < m_MaxElements; i++)
		    pElement->pPrev = pElement - 1;
		    pElement->pnext = pElement + 1;
		    pElement ++;
	    // We don't have a next element
	    pElement.pNext = 0;
    template <class T>

Now the code compiles without a problem. I wanted to test if the constructor works so I created a file, added a main function
#include <iostream>

#include "CWStackAllocator.h"

using namespace std;
using namespace CWolf;

int main()
    CWStackAllocator<int> test;
    cout << "Hello world!" << endl;
    return 0;

But now when I try to compile I get the following errors:

1>main.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall CWolf::CWStackAllocator<int>::~CWStackAllocator<int>(void)" (??1?$CWStackAllocator@H@CWolf@@UAE@XZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall CWolf::CWStackAllocator<int>::CWStackAllocator<int>(unsigned int)" (??0?$CWStackAllocator@H@CWolf@@QAE@I@Z) referenced in function _main
1>c:\...\MemoryManager.exe : fatal error LNK1120: 2 unresolved externals

Any idea why this is happening?

3D Planes

23 June 2011 - 02:08 PM

Im using a verry simple function to draw planes. I want to use those planes as floors, ceilings and walls.When im using it as floors and ceiling it works great. But when I'm using it as walls sometimes the walls are invisible.

CWOLF double CWDrawPlane(double x1, double y1, double z1, double x2, double y2, double z2,double texid, double vrepeat, double hrepeat)
    if (glIsTexture((int)texid)){
            glBindTexture(GL_TEXTURE_2D, (int)texid);
    glColor3f(1.0f, 1.0f, 1.0f);
    glTexCoord2f(0.0, hrepeat);glVertex3f(x1, z1, y1);
    glTexCoord2f(vrepeat, hrepeat);glVertex3f(x2, z1, y1);
    glTexCoord2f(vrepeat, 0.0);glVertex3f(x2, z2, y2);
    glTexCoord2f(vrepeat, 0.0);glVertex3f(x2, z2, y2);
    glTexCoord2f(0.0, 0.0);glVertex3f(x1, z2, y2);
    glTexCoord2f(0.0, hrepeat);glVertex3f(x1, z1, y1);
I have horisontal walls and vertical walls. The vertical ones aren't being drawn.
|      ___   <- visible|
| 	|              |
| 	|   <- invisble|
|                      |
|                      |

Here are the x, y and z's of the horisontal wall ( which is being drawn )

And here are those of the vertical wall ( which isn't drwan )

x and y is the center of the wall

Any help fixing the function appretiated.

EDIT: Culling is disabled.
          _________(x2, y2, z2)
          |        |
(x1, y1, z1)


24 April 2011 - 03:34 AM

I have loaded 4 vertices and 4 texture coordinates in VBO 's

[left]CWPlane = new CWVertex[4];

	CWPlane[0].x = 1.0f;CWPlane[0].y = 0.0f;CWPlane[0].z = 1.0f;
	CWPlane[1].x = 1.0f;CWPlane[1].y = 0.0f;CWPlane[1].z = 0.0f;
	CWPlane[2].x = 0.0f;CWPlane[2].y = 0.0f;CWPlane[2].z = 0.0f;
	CWPlane[3].x = 0.0f;CWPlane[3].y = 0.0f;CWPlane[3].z = 1.0f;
	CWPlaneTex = new CWTextCoord[4];
	CWPlaneTex[0].u = 1.0f;CWPlaneTex[0].v = 1.0f;
	CWPlaneTex[1].u = 1.0f;CWPlaneTex[1].v = 0.0f;
	CWPlaneTex[2].u = 0.0f;CWPlaneTex[2].v = 0.0f;
	CWPlaneTex[3].u = 0.0f;CWPlaneTex[3].v = 1.0f;

		glGenBuffersARB = (PFNGLGENBUFFERSARBPROC) wglGetProcAddress("glGenBuffersARB");
		glBindBufferARB = (PFNGLBINDBUFFERARBPROC) wglGetProcAddress("glBindBufferARB");
		glBufferDataARB = (PFNGLBUFFERDATAARBPROC) wglGetProcAddress("glBufferDataARB");
		glMapBufferARB = (PFNGLMAPBUFFERARBPROC) wglGetProcAddress("glMapBufferARB");
		glUnmapBufferARB = (PFNGLUNMAPBUFFERARBPROC)wglGetProcAddress("glUnmapBufferARB");
		glDeleteBuffersARB = (PFNGLDELETEBUFFERSARBPROC) wglGetProcAddress("glDeleteBuffersARB");
    	glGenBuffersARB(3, CWPrimitives);
    	glBindBufferARB(GL_ARRAY_BUFFER_ARB, CWPrimitives[0]);
    	glBufferDataARB(GL_ARRAY_BUFFER_ARB, 4*3*sizeof(float), CWPlane, GL_STATIC_DRAW_ARB );
    	glGenBuffersARB(3, CWPrimitivesText );// Get A Valid Name
		glBindBufferARB(GL_ARRAY_BUFFER_ARB, CWPrimitivesText[0]);// Bind The Buffer
    	glBufferDataARB(GL_ARRAY_BUFFER_ARB, 4*2*sizeof(float), CWPlaneTex, GL_DYNAMIC_DRAW_ARB );

Now I want to be able to change the texture coordinates every frame.The above code creates a textured plane. This is how I draw it
[left]CWPlaneTex[0].u  = (float)vrepeat;CWPlaneTex[0].v  = (float)hrepeat;
	CWPlaneTex[1].u  = (float)vrepeat;CWPlaneTex[3].v  = (float)hrepeat;
	glBindTexture(GL_TEXTURE_2D,  (int)texid);
	if (g_fVBOSupported == true) {
    	glBindBufferARB(GL_ARRAY_BUFFER_ARB, CWPrimitives[0]);
    	glVertexPointer(3, GL_FLOAT, 0, (char *) NULL );// Set The Vertex Pointer To The Vertex Buffers
    	glBindBufferARB( GL_ARRAY_BUFFER_ARB, CWPrimitivesText[0]);
    	glBufferDataARB(GL_ARRAY_BUFFER_ARB, 4*2*sizeof(float), CWPlaneTex, GL_DYNAMIC_DRAW_ARB );
    	glTexCoordPointer(2, GL_FLOAT, 0, (char *) NULL );// Set The TexCoord Pointer To The TexCoord Buffer
	} else {
		glVertexPointer(3, GL_FLOAT, 0, CWPlane);// Set The Vertex Pointer To Our Vertex Data
		glTexCoordPointer( 2, GL_FLOAT, 0, CWPlaneTex );// Set The Vertex Pointer To Our TexCoord Data
	glTranslatef(x1, z1, y1);
	glScalef(x2 - x1, z2 - z1, y2 - y1);
	glColor3f(1, 1, 1);
	glDrawArrays(GL_QUADS, 0, 4);// Draw All Of The Triangles At Once

Right now I'm using glBufferDataARB(GL_ARRAY_BUFFER_ARB, 4*2*sizeof(float), CWPlaneTex, GL_DYNAMIC_DRAW_ARB ); and it works perfect. Why doesn't
glBufferSubData(GL_ARRAY_BUFFER_ARB, 0, 4*2*sizeof(float), CWPlaneTex);work?

Transparent Texture

09 April 2011 - 03:19 AM

I'm setting an ortho projection and am drawing a texture plane. Now I want the texture for that plane to be transparent.
	ILuint image = 0;
	ilGenImages(1, &image);
	int w = ilGetInteger(IL_IMAGE_WIDTH);
	int h = ilGetInteger(IL_IMAGE_HEIGHT);
	BYTE *bits = new BYTE[w * h * 4];
	ilCopyPixels(0, 0, 0, w, h, 1, IL_RGBA, IL_UNSIGNED_BYTE, bits);
	GLuint textureID[1];
	glGenTextures(1, &textureID[0]);//generate texture
	glBindTexture(GL_TEXTURE_2D, textureID[0]);//work with this texture
        	GL_LINEAR  );//set the min filter
        	GL_LINEAR  );//set the mag filter
    	glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)bits);
I use DeviL to load the image. The image in question is this:
Posted Image

Following an article I found on opengl's site

So thats what im doing.Blending is disabled (glDisable(GL_BLEND). I set up the texture environment like it says in the article.
int w, h;
	glBindTexture(GL_TEXTURE_2D, (int)textid);
	glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w);
	glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h);
	glTexCoord2i(0, 1);glVertex2f(x, y);
	glTexCoord2i(0, 0);glVertex2f(x, y + h);
	glTexCoord2i(1, 0);glVertex2f(x + w, y + h);
	glTexCoord2i(1, 1);glVertex2f(x + w, y);

This is the code I use to draw my plane. with that the result i get is :


This is what I want to get:

Can anyone help me? The block color is how it should be. And the alpha is being loaded correctly. Its values from 0 to 255.