Jump to content

  • Log In with Google      Sign In   
  • Create Account

MaxFire

Member Since 09 Jun 2011
Online Last Active Today, 04:52 AM

Topics I've Started

C++ Serialize OpengGL pixel data in bitmap formatted byte array

14 October 2014 - 01:40 PM

Hi guys,

 

Im trying to send a screenshot to a remote device using TCP. My networking is working fine however I am unable to serialize the OpenGL pixel data into a format that can be de-serialized into a bitmap image on the client. I am using a Bitmap to keep it simple without compression at the moment.

 

My current attempt is using FreeImage as it is cross platform but would not mind switching Image framework. 

		glReadPixels( 0, 0, g_iScreenWidth, g_iScreenHeight, GL_RGB, GL_UNSIGNED_BYTE, g_pixels );

		FIBITMAP* image = FreeImage_ConvertFromRawBits( g_pixels, g_iScreenWidth, g_iScreenHeight, 3 * g_iScreenWidth, 24, 0xFFFF0000, 0xFF008000, 0xFF0000FF, false );

		FIBITMAP *src = FreeImage_ConvertTo32Bits( image );
		FreeImage_Unload( image );
		// Allocate a raw buffer
		int width = FreeImage_GetWidth( src );
		int height = FreeImage_GetHeight( src );
		int scan_width = FreeImage_GetPitch( src );
		BYTE *bits = ( BYTE* ) malloc( height * scan_width );
		FreeImage_ConvertToRawBits( bits, src, scan_width, 24, 0xFFFF0000, 0xFF008000, 0xFF0000FF, false );
		FreeImage_Unload( src );

		g_pTCPServer->SendDataToClientsBytes( bits, height * scan_width );

However this does not give me a byte format that can be de-serialized as a bitmap image on a c# application.

 

Any advice on how I can get the correct format would be appreciated smile.png.

 

Thanks


Unity CG Custom Sader for Texture Layering using Passes

28 October 2013 - 04:01 AM

This is what I’m trying to accomplish

  1. Texture geometry with primary shader
  2. Layer a second texture over the first one by a projected amount following the normal.

Here is my current shader code:

Shader "Custom/FurShader"
{

Properties

{

_MainTex( "Main Texture", 2D ) = "white" {}

_MaxHairLength( "Max Hair Length", Float ) = 0.5

_NoOfPasses( "Number of Passes", Float ) = 2.0

}



CGINCLUDE

//includes

#include "UnityCG.cginc"



//structures

struct vertexInput

{

float4 vertex : POSITION;

float4 normal : NORMAL;

float4 texcoord : TEXCOORD0;

};



struct fragmentInput

{

float4 pos : SV_POSITION;

half2 uv : TEXCOORD0;

};



//uniforms

uniform float _MaxHairLength;

uniform sampler2D _MainTex;

uniform float4 _MainTex_ST;



uniform sampler2D _SecondTex;

uniform float4 _SecondTex_ST;



uniform float _NoOfPasses;



//function

inline fragmentInput LevelFragmentShader( vertexInput i, int level )

{

fragmentInput o;



float movementDist = ( _MaxHairLength / _NoOfPasses ) * level;



float4 pos = ( i.vertex + ( i.normal * movementDist ) );



o.pos = mul( UNITY_MATRIX_MVP, pos );

o.uv = TRANSFORM_TEX( i.texcoord, _SecondTex );



return o;

}



half4 frag( fragmentInput i ) : COLOR

{

return tex2D( _SecondTex, i.uv );

}



ENDCG



SubShader {

Tags { "Queue" = "Transparent"}

Blend SrcAlpha OneMinusSrcAlpha



Pass

{

CGPROGRAM

// Upgrade NOTE: excluded shader from OpenGL ES 2.0 because it does not contain a surface program or both vertex and fragment programs.

#pragma exclude_renderers gles

#pragma vertex vert

#pragma fragment frag_unique



fragmentInput vert( vertexInput i )

{

fragmentInput o;



o.pos = mul( UNITY_MATRIX_MVP, i.vertex );

o.uv = TRANSFORM_TEX( i.texcoord, _MainTex );



return o;

}



half4 frag_unique( fragmentInput i ) : COLOR

{

return tex2D( _MainTex, i.uv );

}





ENDCG

}

Pass

{

CGPROGRAM

// Upgrade NOTE: excluded shader from OpenGL ES 2.0 because it does not contain a surface program or both vertex and fragment programs.

#pragma exclude_renderers gles

#pragma vertex vert

#pragma fragment frag



fragmentInput vert( vertexInput i )

{

fragmentInput o = LevelFragmentShader( i, 1 );



return o;

}





ENDCG

}



}

FallBack "Diffuse"

} 

But as you can see the result second texture is not projecting perpendicularly edge to edge. Any suggestions would be great, im sure my maths is correct vertxPos + ( Normal * projectionDistance). Could it be something to do with how im using unitys ModelViewProjection Matrix?

Image showing result http://i1265.photobucket.com/albums/jj508/maxfire1/Capture_zpsc8db2b1f.png

Thanks in advanced


Blender animation help

30 November 2012 - 07:00 AM

Hi guys I need some help with animating my model, so I have been following a few animation tutorials which include rigging, weighting and animating but no matter what I try I can not get the mesh to move with the bones correctly. Either the bones move more than the mesh or the mesh moves more than the bones, both causing horrible transformation effects.

I have double checked all my weights but they all seem fine with little to none overlap :(

Attached a screen shot of the problem..

Now I have done some searching before I came here, my presumption is that its a problem with the armature modifier.. but I have no idea what this is haha

Thanks again

http://i1265.photobucket.com/albums/jj508/maxfire1/Capture.png
Max

Basic animation for an XNA project using autocad 3D max

21 October 2012 - 03:51 PM

Hi guys so here is my problem

I'm currently working on a simple XNA project consisting of a 3rd person camera, but now I need a character model to sit in front. So I chose 3D studio max as my design packaged and watched all the provided tutorials on the basic controls, objects creating and transformations.

This is where I have become stuck, no where can I find any decent tutorials that take me through the stages of setting up bone structure and then creating multiple animations in a single model. Every tutorial I read/watch shows me basic animation on a single time line using time stamp keys.

So here is my question
Can some one point me in the right direction in which I can find some good tutorials on setting up bones/multiple animations ?

Xcode 4 with SDL

09 August 2012 - 04:39 PM

Hi gys im seeking help from someone who knows about the OSX xcode 4 compiler and runtime

Ok so Im a big fan of SDL and have used it on windows form nearly a year now. After some research I found that the iphone could compile c++ so I have been triyng to get SDL working with xcode 4 on my mac.

after a bit of research I found there is very little help on trying to do this for xcode 4. But from my knowledge from windows it accrued to me that all I really needed to do was add the SDL framework to the project then make the header files visible to the compiler.

This was fairly easy to do a simple test program compiles no problem. Now I hit the hurdle when trying to run the program I get the error message

dyld: Library not loaded: @executable_path/../Frameworks/SDL.framework/Versions/A/SDL

Referenced from: /Users/maxashton/Library/Developer/Xcode/DerivedData/SDL_Test-aolpwbzxuhkmfgategasbecconuo/Build/Products/Debug/SDL_Test.app/Contents/MacOS/SDL_Test

Now from my my knowledge from windows I know that the SDL.dlls have to be in a location which the runtime can see (project folder or system32).

could it be that I am missing the dll equivalent for OSX? if so where could I find these they dont come in the download and the SDL framework isn't something I can compile to create them myself.

Thanks for the help in advanced :)

PARTNERS