Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 08 Nov 2007
Offline Last Active Oct 22 2014 05:07 PM

Topics I've Started

Generating a checkered pattern via dynamic textures in D3D9

22 October 2014 - 03:36 PM

I haven't been on here in awhile, anyways, I need some assistance with creating a checkered pattern texture to use as a default texture when textures can't be loaded from disk. I am using this code:

		d3dText->LockRect(0, &lockRect, 0, D3DLOCK_DISCARD);

		for (unsigned int i = 1; i <= d3dText->Width / 64; ++i)
			for (unsigned int j = 1; j <= d3dText->Height / 64; ++j)
				BYTE* data = (BYTE*)lockRect.pBits;
				int index = i * lockRect.Pitch / 4 + j;

				if ((i + j % 2) == 1)
					data[index++] = 255;
					data[index++] = 0;
					data[index++] = 0;
					data[index++] = 255;
					data[index++] = 255;
					data[index++] = 255;
					data[index++] = 255;
					data[index++] = 255;

the texture is dynamic and everything but when I try to save it for debugging purposes, the texture's just......white. Nothing wrong with that but I need a checkered pattern to use as a default texture.

Having a problem getting data from .obj file to render (index / Vertex buffer prob)

09 July 2014 - 06:19 PM

I've tried everything I could think of, every possible thing and yet, I can't get the .obj mesh to render. It gets all the vertices and indices (I think.) But when I try to pass it on to DIrect3D9's vertex and index buffers, it.....doesn't go well. Here's a few links and my explanation.


meshobj.cpp file:


(note: to keep this post short, I'll be using pastbin for code.)




mesh.obj file:




and finally: a screen shot of what PIX shows.....




as you can see, the vertices don't seem to be pushed through the pipeline right...I've given all I can give to explain this problem. If you could help me out, I'd appreciate it. let me know if you need to see something else.



Having trouble with my Vertex Element Class

03 May 2014 - 12:43 AM

OK, I'm trying to make it so all you have to do to add a new vertex element is this:

void Shape::setVertexElement(string semanticName, unsigned int semanticIndex, unsigned int format, unsigned int inputSlot, unsigned int inputSlotClass, unsigned int alignedByteOffset, unsigned int instanceDataStepRate)
	VertexElement* vertElem = new VertexElement(semanticName, semanticIndex, format, inputSlot, inputSlotClass, alignedByteOffset, instanceDataStepRate);

than, updating them like this:

void Shape::createInputlayout()
	D3D11_INPUT_ELEMENT_DESC* elemDesc = new D3D11_INPUT_ELEMENT_DESC[this->m_vertexElements.size() - 1];

	VertexElements::iterator i;
	unsigned int x;
	for (x = 0, i = m_vertexElements.begin(); i != m_vertexElements.end(); ++i, ++x)
		elemDesc[x].SemanticName = static_cast<LPCSTR>(i->getSemanticName().c_str());
		elemDesc[x].SemanticIndex = i->getSemanticIndex();
		elemDesc[x].Format = static_cast<DXGI_FORMAT>(i->getFormat());
		elemDesc[x].InputSlot = i->getInputslot();
		elemDesc[x].InputSlotClass = static_cast<D3D11_INPUT_CLASSIFICATION>(i->getInputSlotClass());
		elemDesc[x].InstanceDataStepRate = i->getInstanceDataStepRate();
		elemDesc[x].AlignedByteOffset = i->getAlignedByteOffset();
	if (m_hardwareMaterial != NULL)
		HRESULT hr = m_device->CreateInputLayout(elemDesc, (unsigned int)m_vertexElements.size(), m_hardwareMaterial->getVertexShaderBlob()->GetBufferPointer(), m_hardwareMaterial->getVertexShaderBlob()->GetBufferSize(), &m_inputlayout);

		if (FAILED(hr))
			const char* err = DXGetErrorDescriptionA(hr);

			MessageBoxA(NULL, err, NULL, MB_OK);


How ever, for some reason, Direct3D says this:

D3D11 ERROR: ID3D11Device::CreateInputLayout: Element[1] and Element[0] have the same Semantic ( 0).  All Semantics in the Input Layout must be unique.  This error is only printed on the first occurence detected. [ STATE_CREATION ERROR #160: CREATEINPUTLAYOUT_DUPLICATESEMANTIC]

It seems like the string from the class isn't updating right. I wonder if I'm doing it wrong or you can't do it this way. (I was trying to do it like Ogre's vertex declaration, but they do it with Direct3D9. I thought it would be the same concept, since all you'd have to do is iterator through the vector and set the elements[x] to what ever the iterator holds.)

Getting rid of the pesky error C2027: Use of undefined type.

24 April 2014 - 11:17 PM

Ok, maybe it's just me, (very likely, actually) But I Can never seem to get include files right and class declarations, and such.....Seriously, it's like I'm doing something wrong in visual studio, or maybe linking classes wrong, maybe not closing the header files right, I don't know. I'm going to upload my project on here to try to get some help on it, maybe some tips on how to make sure this NEVER happens again, because this has been the bane of my existence for as long as I've been a programmer. I cannot get past it. please, help me in making sure this never happens again....


Notes about the project: uses Direct3D11 + windows, no external libs used. 


Note 1.1: let me know if you need something else to get this to work but you shouldn't have a problem. Really hope to get some advice on this as it has driven me insane in the past.

A very annoying syntax Error and isn't an error.

29 December 2013 - 04:29 PM

C:\Users\Rosario\Desktop\Converge 8.0\Projects\OpenGL\main.cpp|278|error: expected primary-expression before ',' token|

This error comes after using this function:

      //  char buffer[256];
     //   sprintf(buffer,"Collision: ",true);
    //    drawText(SCREEN_WIDTH/2,SCREEN_HEIGHT/2,buffer,1,1,1,1);

Now, I've looked through the function and everything seems in order. I might be missing something....Here's the function definition for your viewing pleasure:

bool EntityManager::checkCollisionBoundingBox(Entity* ent1, Entity* ent2)
    bool ret = false;
    Entities::iterator first;
    Entities::iterator second;

    Rectangle* rA = new Rectangle();
    Rectangle* rB = new Rectangle();

    first = mEntites.begin();
    while(first != mEntites.end())
        ent1 = (*first);
            second = mEntites.begin();
            while(second != mEntites.end())
                ent2 = (*second);
                if(ent2->isVisible() && ent1 != ent2)
                    // set the first rect.
                    rA->setLeft(ent1->getRectangle()->getLeft() + ent1->getXpos());
                    rA->setTop(ent1->getRectangle()->getTop() + ent1->getYpos());
                    rA->setRight(ent1->getRectangle()->getRight() + ent1->getRectangle()->getWidth() + ent1->getXpos() * ent1->getScale().getX());
                    rA->setBottom(ent1->getRectangle()->getBottom() + ent1->getRectangle()->getLength() + ent1->getYpos() * ent1->getScale().getY());

                    // set the second;
                    rB->setLeft(ent2->getRectangle()->getLeft() + ent2->getXpos());
                    rB->setTop(ent2->getRectangle()->getTop() + ent2->getYpos());
                    rB->setRight(ent2->getRectangle()->getRight() + ent2->getRectangle()->getWidth() + ent2->getXpos() * ent2->getScale().getX());
                    rB->setBottom(ent2->getRectangle()->getBottom() + ent2->getRectangle()->getLength() + ent2->getYpos() * ent2->getScale().getY());

                    if (rA->isInside( rB->getLeft(), rB->getTop() ) ||
                        rA->isInside( rB->getRight(), rB->getTop() ) ||
                        rA->isInside( rB->getLeft(), rB->getBottom() ) ||
                        rA->isInside( rB->getRight(), rB->getBottom() ))
                            ret = true;
    delete rA;
    delete rB;
    return ret;

Now sure if there's a syntax error in the function it self or not. I'm using code:blocks 12.11 with the  GNU GCC compiler. Please let me know what I did wrong, chances are.....I did something wrong.