Jump to content

  • Log In with Google      Sign In   
  • Create Account


CirdanValen

Member Since 05 Jul 2009
Offline Last Active Jul 22 2013 12:14 AM
-----

Topics I've Started

GLSL vec4 multiplication not working?

24 June 2013 - 09:04 PM

I'm having a problem with my shader causing my texture to render transparent. As you can see in the top 2 windows, the text is rendered correctly when I just use the image data. However, in the bottom half, the text is not rendered at all when I try to multiply a color. No shader errors at all.

 

2vAKWfG.png


Why is this a function on distance and not angle?

13 January 2013 - 01:12 PM

I'm trying to create a billboard that faces the camera, following the Lighthouse3d tutorial and it really isn't working at all.
        glm::vec3 campos = state->getCamera()->getPosition();
        glm::vec3 objToCam = campos - mPosition;
        objToCam = glm::normalize(objToCam);

        glm::vec3 upAux = glm::cross(glm::vec3(0.f, 0.f, 1.f), objToCam);
        float angleCos = glm::dot(glm::vec3(0.f, 0.f, 1.f), objToCam);

        glm::vec3 rot;
        rot.y = glm::degrees(glm::acos(angleCos));
       
        // First translate so we rotate around the center of the billboard
        glm::mat4 rotMatrix = glm::translate(glm::mat4(), glm::vec3(-16.f, 0.f, 0.f));
        rotMatrix = glm::rotate(rotMatrix, rot.y, upAux);

This isn't working as expected.

A) The billboard will follow the camera as long as I am not within a few degrees of 0 on the x axis. As I start to close in to 0 the billboard rotates back to face down the X axis.

b) Rotation of the billboard becomes whacky when I only increase the distance. It starts rotating by large amounts, and faces away from the camera.

Moving camera in direction of rotation

05 January 2013 - 12:15 AM

I'm trying to get my camera to move in the direction of it's rotation. My code is mostly working, but I have one problem and I'm not sure how to fix it. I'm trying to make the camera move in any direction on the horizontal plane and up and down on the vertical plane. No rolling. My problem is, when the camera is facing straight up (or close to it) the camera continue to moves on the horizontal plane instead vertically. I don't know how to make it so as the pitch get's closer to 90/-90, the movement on the horizontal plane becomes less and less. Here is my code so far:

void ITransformable::moveInRotation(float distance) {
   
    float x = 0.f;
    float z = 0.f;
    float y = 0.f;

    
    if(mRotation.x < DEGREES_TO_RADIANS(45.f)) {
        y = std::sin(mRotation.x) * distance;
    } else {
        y = std::cos(mRotation.x) * distance;
    }

    if(mRotation.y >= DEGREES_TO_RADIANS(90.f)) {
        mRotation.y -= DEGREES_TO_RADIANS(90.f);
    }

    if(mRotation.y < DEGREES_TO_RADIANS(45.f)) {
        x = std::sin(mRotation.y) * distance;

        // Find the adjacent side, which is our distance on the x-axis
        z = std::cos(mRotation.y) * distance;
    } else {
        z = std::sin(mRotation.y) * distance;
        x = std::cos(mRotation.y) * distance;
    }

    translate(x, -y, z);
}

Awesomium 1.7RC2: BitmapBuffer::CopyTo failing?

14 August 2012 - 10:11 PM

EDIT: Sovled the problem. Needed to enable texturing -.-

Hey guys, I'm trying to see if I can get Awesomium working and have run into a problem.

In my loop, I have this block of code. "view" is an Awesomium WebView

		if(view->IsLoading()) {
			awesomiumCore->Update();
			Sleep(10);
			std::cout << "Loading..." << std::endl;
		} else {
		
			const Awesomium::BitmapSurface *bitmap = static_cast<const Awesomium::BitmapSurface*>(view->surface());
		
			if(bitmap->is_dirty()) {
				awesomiumCore->Update();
				std::cout << "Done loading." << std::endl;
				saved = true;
		

				if(bitmap == NULL) {
					std::cout << "Failed to render page." << std::endl;
				} else {
					bitmap->SaveToPNG(Awesomium::WebString::CreateFromUTF8("google.png", strlen("google.png")), false);

					glGenTextures(1, &texture);
					glBindTexture(GL_TEXTURE_2D, texture);

					glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
					glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
					glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
					glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
				
					bitmap->CopyTo(buffer, 1024*4, 4, true, false);

					glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1024, 768, 0, GL_BGRA, GL_UNSIGNED_BYTE, buffer);

				}
			}

		}

This code works fine, and the PNG that get's saved is the expected output. However, it seems that when I copy to the buffer, the resulting buffer is empty. I'm trying to render the web page out to OpenGL, but all I'm getting is a white quad.

Copying pixel data

12 July 2012 - 12:25 AM

I'm trying to write some code to copy a smaller section of a bigger image to a new image for use in my game. I'm using SFML to load the image from the file. I know the format of the pixels are RGBA and are stored in a block of memory sized as width*height*4. I assume this means that each pixel is 4 bytes(1 bit per color).

Texture* AssetLoader::getSubTexture(const std::string &name, int x, int y, int w, int h) {
	sf::Image image;

	if(!image.loadFromFile(name)) {
		return NULL;
	}
	
	// Get the pointer for the image's pixels
	const unsigned char *pixels = image.getPixelsPtr();

	// Create new buffer for our new image
	unsigned char *newImage = (unsigned char*)malloc(w * h * 4);
	unsigned int imageWidth = image.getSize().x; // Pixels per row
	unsigned int imageHeight = image.getSize().y; // Pixels per column

	// Copy the pixels into the new image
	for(unsigned int row = y; row <= y+h; row++) {

			unsigned int index = x + (row*imageWidth);
			
			// Copy the entire row of pixels
			memcpy(&newImage[(row-y)*w], &pixels[index], w*96);
	}

	Texture* result = new Texture((const void*)newImage, w, h);
	delete[] newImage;
	return result;
}


This code works for my current testing situation. The image I'm testing on is 32x32. The portion of the image I'm copying with this method is (0,0,32,32).

memcpy(&newImage[row*w], &pixels[index], w*96);

With this code, I'm trying to copy an entire row of pixels into the new buffer. I would assume that, to copy an entire row of pixels, the size of memory I'm copying would be widthOfImage*4bytes. However, this only copies the fist few lines of the image and stops. When I do w*96 as in my example, the entire image gets copied. Of course, this breaks down if I try to copy a different size image.

My question is, what is happening here and how do I properly copy the pixels? I can't seem to figure out where the number 96*32 comes from that makes the image load fully.

32x32x4 = 4096
96*32 = 3072
----
1024

PARTNERS