Skip to content

Commit 5703d5a

Browse files
committed
Added sources
1 parent 51260fb commit 5703d5a

14 files changed

+740
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SpoutAE/x64/Debug/
2+
*.sdf

SpoutAE/ReadMe.txt

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
========================================================================
2+
DYNAMIC LINK LIBRARY : SpoutAE Project Overview
3+
========================================================================
4+
5+
AppWizard has created this SpoutAE DLL for you.
6+
7+
This file contains a summary of what you will find in each of the files that
8+
make up your SpoutAE application.
9+
10+
11+
SpoutAE.vcxproj
12+
This is the main project file for VC++ projects generated using an Application Wizard.
13+
It contains information about the version of Visual C++ that generated the file, and
14+
information about the platforms, configurations, and project features selected with the
15+
Application Wizard.
16+
17+
SpoutAE.vcxproj.filters
18+
This is the filters file for VC++ projects generated using an Application Wizard.
19+
It contains information about the association between the files in your project
20+
and the filters. This association is used in the IDE to show grouping of files with
21+
similar extensions under a specific node (for e.g. ".cpp" files are associated with the
22+
"Source Files" filter).
23+
24+
SpoutAE.cpp
25+
This is the main DLL source file.
26+
27+
When created, this DLL does not export any symbols. As a result, it
28+
will not produce a .lib file when it is built. If you wish this project
29+
to be a project dependency of some other project, you will either need to
30+
add code to export some symbols from the DLL so that an export library
31+
will be produced, or you can set the Ignore Input Library property to Yes
32+
on the General propert page of the Linker folder in the project's Property
33+
Pages dialog box.
34+
35+
/////////////////////////////////////////////////////////////////////////////
36+
Other standard files:
37+
38+
StdAfx.h, StdAfx.cpp
39+
These files are used to build a precompiled header (PCH) file
40+
named SpoutAE.pch and a precompiled types file named StdAfx.obj.
41+
42+
/////////////////////////////////////////////////////////////////////////////
43+
Other notes:
44+
45+
AppWizard uses "TODO:" comments to indicate parts of the source code you
46+
should add to or customize.
47+
48+
/////////////////////////////////////////////////////////////////////////////

SpoutAE/Spout2Helper.h

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
#include <Spout.h>
2+
3+
HWND hWnd;
4+
5+
bool InitGLtexture(GLuint &texID, unsigned int width, unsigned int height)
6+
{
7+
// printf("testApp::InitGLtexture %dx%d\n", width, height);
8+
9+
if(texID != 0) glDeleteTextures(1, &texID);
10+
11+
glGenTextures(1, &texID);
12+
glBindTexture(GL_TEXTURE_2D, texID);
13+
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
14+
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
15+
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
16+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
17+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
18+
glBindTexture(GL_TEXTURE_2D, 0);
19+
20+
return true;
21+
}
22+
23+
24+
void bitmapDataToGL(GLuint &texID, int width, int height, GLvoid * pixels)
25+
{
26+
glBindTexture(GL_TEXTURE_2D, texID);
27+
28+
29+
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,GL_BGRA_EXT, GL_UNSIGNED_BYTE,pixels);
30+
31+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // GL_LINEAR);
32+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // GL_LINEAR);
33+
34+
glBindTexture(GL_TEXTURE_2D, 0);
35+
glDisable(GL_TEXTURE_2D);
36+
}
37+
38+
39+
void GLToBitmapData(GLuint &texID, int width, int height, GLvoid * pixels)
40+
{
41+
glBindTexture(GL_TEXTURE_2D, texID);
42+
glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, pixels);
43+
glBindTexture(GL_TEXTURE_2D,1);
44+
}
45+
46+
47+
//GL INIT / CONTEXT CREATION
48+
BOOL CALLBACK EnumProc(HWND hwnd, LPARAM lParam)
49+
{
50+
DWORD windowID;
51+
GetWindowThreadProcessId(hwnd, &windowID);
52+
53+
if (windowID == lParam)
54+
{
55+
printf("Found HWND !\n");
56+
hWnd = hwnd;
57+
58+
return false;
59+
}
60+
61+
return true;
62+
}
63+
64+
65+
void EnableOpenGL(HWND hWnd, HDC * hDC, HGLRC * hRC)
66+
{
67+
PIXELFORMATDESCRIPTOR pfd;
68+
int iFormat;
69+
70+
// get the device context (DC)
71+
*hDC = GetDC( hWnd );
72+
73+
// set the pixel format for the DC
74+
ZeroMemory( &pfd, sizeof( pfd ) );
75+
pfd.nSize = sizeof( pfd );
76+
pfd.nVersion = 1;
77+
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL |
78+
PFD_DOUBLEBUFFER;
79+
pfd.iPixelType = PFD_TYPE_RGBA;
80+
pfd.cColorBits = 24;
81+
pfd.cDepthBits = 16;
82+
pfd.iLayerType = PFD_MAIN_PLANE;
83+
iFormat = ChoosePixelFormat( *hDC, &pfd );
84+
SetPixelFormat( *hDC, iFormat, &pfd );
85+
86+
// create and enable the render context (RC)
87+
*hRC = wglCreateContext( *hDC );
88+
wglMakeCurrent( *hDC, *hRC );
89+
}
90+
91+
void DisableOpenGL(HWND hWnd, HDC hDC, HGLRC hRC)
92+
{
93+
wglMakeCurrent( NULL, NULL );
94+
wglDeleteContext( hRC );
95+
ReleaseDC( hWnd, hDC );
96+
}
97+
98+
99+
bool InitGL() // All Setup For OpenGL Goes Here
100+
{
101+
102+
printf("InitGL with EnabledOpenGL\n");
103+
104+
//set hWnd with process ID
105+
DWORD processID = GetCurrentProcessId();
106+
EnumWindows(EnumProc, processID);
107+
108+
109+
HDC hDC;
110+
HGLRC glContext;
111+
EnableOpenGL(hWnd,&hDC,&glContext);
112+
113+
// Determine hardware capabilities now, not later when all is initialized
114+
// =====================================================
115+
//glContext = wglGetCurrentContext(); // should check if opengl context creation succeed
116+
if(glContext) {
117+
printf("GL Context creation OK\n");
118+
}
119+
else {
120+
121+
printf("No GL context, GetLastError : %X\n",GetLastError());
122+
123+
return false;
124+
}
125+
126+
printf("And we are there !\n");
127+
128+
return true; // Initialization Went OK
129+
130+
}

SpoutAE/SpoutAE.cpp

+165
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
// SpoutAE.cpp : Defines the exported functions for the DLL application.
2+
//
3+
4+
#include "SpoutAE.h"
5+
#include "Spout2Helper.h"
6+
7+
8+
int tWidth = 0;
9+
int tHeight = 0;
10+
bool texInit = false;
11+
bool firstInit = false;
12+
13+
SpoutSender sender;
14+
GLuint texID;
15+
16+
#ifdef AE_OS_WIN
17+
BOOL APIENTRY LibMain(HANDLE hInstance, DWORD fdwReason, LPVOID lpReserved)
18+
{
19+
printf("SpoutAE.aex Initialization entry point.");
20+
return TRUE;
21+
}
22+
#endif
23+
24+
25+
26+
27+
static PF_Err
28+
MyBlit(
29+
void *hook_refconPV,
30+
const AE_PixBuffer *pix_bufP0,
31+
const AE_ViewCoordinates *viewP,
32+
AE_BlitReceipt receipt,
33+
AE_BlitCompleteFunc complete_func0,
34+
AE_BlitInFlags in_flags,
35+
AE_BlitOutFlags *out_flags)
36+
{
37+
38+
if(pix_bufP0->widthL != (tWidth-4) || pix_bufP0->heightL != (tHeight+4))
39+
{
40+
texInit = false;
41+
}
42+
43+
//printf("Blit : %i %i %i %i %i\n",pix_bufP0->widthL,pix_bufP0->heightL,pix_bufP0->depthL,pix_bufP0->plane_bytesL,pix_bufP0->chan_bytesL);
44+
45+
if(!texInit)
46+
{
47+
//printf("texInit !\n");
48+
tWidth = pix_bufP0->widthL+4;
49+
tHeight = pix_bufP0->heightL-4;
50+
51+
52+
InitGLtexture(texID,tWidth,tHeight);
53+
54+
bool bTextureShare = false;
55+
56+
57+
58+
if(!firstInit)
59+
{
60+
texInit = sender.CreateSender("AfterFX", tWidth,tHeight);
61+
//texInit = spout.InitSender("AE", tWidth,tHeight,bTextureShare,false);
62+
firstInit = true;
63+
}
64+
65+
//printf("TexInit OK !\n");
66+
texInit = true;
67+
68+
}
69+
70+
if(texInit)
71+
{
72+
73+
PF_Pixel8 * pixels = (PF_Pixel8 *) pix_bufP0->pixelsPV;
74+
PF_Pixel8 * pixels2 = (PF_Pixel8 *)malloc(tWidth*tHeight*sizeof(PF_Pixel8));
75+
76+
memcpy(pixels2,pixels,tWidth*tHeight*sizeof(PF_Pixel8));
77+
78+
for(int y=0; y<tHeight; y++)
79+
{
80+
for(int x=0; x<tWidth; x++)
81+
{
82+
int index = x+y*tWidth;
83+
int index2 = x+(tHeight-1 - y)*tWidth;
84+
pixels2[index].alpha = pixels[index2].blue;
85+
pixels2[index].red = pixels[index2].green;
86+
pixels2[index].green = pixels[index2].red;
87+
pixels2[index].blue = pixels[index2].alpha;
88+
}
89+
}
90+
91+
//Spout::Spout::sen
92+
sender.SendImage((unsigned char *)pixels2,tWidth,tHeight);
93+
//bool shareResult = sender.UpdateSender("AfterFX",*)pixels2,tWidth,tHeight);
94+
//printf("Share Result ? %s",shareResult?"OK":"Error");
95+
96+
}
97+
98+
99+
100+
101+
102+
return PF_Err_NONE;
103+
}
104+
105+
static void
106+
MyDeath(
107+
void *hook_refconPV)
108+
{
109+
// free anything you allocated.
110+
}
111+
112+
static void
113+
MyVersion(
114+
void *hook_refconPV,
115+
A_u_long *versionPV)
116+
{
117+
*versionPV = 1;
118+
}
119+
120+
121+
DllExport PF_Err
122+
EntryPointFunc (
123+
A_long major_version,
124+
A_long minor_version,
125+
AE_FileSpecH file_specH,
126+
AE_FileSpecH res_specH,
127+
AE_Hooks *hooksP)
128+
{
129+
PF_Err err = PF_Err_NONE;
130+
hooksP->blit_hook_func = MyBlit;
131+
hooksP->death_hook_func = MyDeath;
132+
hooksP->version_hook_func = MyVersion;
133+
134+
135+
136+
//Temp
137+
138+
AllocConsole();
139+
freopen("CONIN$", "r", stdin);
140+
freopen("CONOUT$", "w", stdout);
141+
freopen("CONOUT$", "w", stderr);
142+
143+
printf("SpoutAE EntryPoint\n");
144+
145+
//Ben - Spout Helpers
146+
InitGL();
147+
148+
sender.CreateSender("AfterFX", tWidth,tHeight);
149+
150+
/*
151+
printf("BlitHook init %i\n",processID);
152+
153+
bool initResult = false;
154+
155+
printf("Init Spout with hwnd : %i\n",hWnd);
156+
157+
initResult = initSpout(hWnd);
158+
159+
printf("> Spout init result : %d\n",initResult);
160+
161+
*/
162+
163+
return err;
164+
}
165+

SpoutAE/SpoutAE.h

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#pragma once
2+
3+
#ifndef SPOUTAE_H
4+
#define SPOUTAE_H
5+
6+
#include "AEConfig.h"
7+
#include "A.h"
8+
#include "AE_Effect.h"
9+
#include "AE_EffectCB.h"
10+
#include "AE_Macros.h"
11+
#include "AE_Hook.h"
12+
#include "entry.h"
13+
14+
#ifdef AE_OS_WIN
15+
#include <stdio.h>
16+
#include <windows.h>
17+
#endif
18+
19+
#define MAJOR_VERSION 1
20+
#define MINOR_VERSION 0
21+
#define BUG_VERSION 0
22+
#define STAGE_VERSION PF_Stage_DEVELOP
23+
#define BUILD_VERSION 0
24+
25+
#define NAME "Spout"
26+
#define DESCRIPTION "Spout Sender"
27+
28+
#include "AE_Hook.h"
29+
30+
#ifndef DllExport
31+
#define DllExport __declspec( dllexport )
32+
#endif
33+
34+
extern "C" {
35+
DllExport PF_Err
36+
EntryPointFunc(
37+
A_long major_version, /* >> */
38+
A_long minor_version, /* >> */
39+
AE_FileSpecH file_specH, /* >> */
40+
AE_FileSpecH res_specH, /* >> */
41+
AE_Hooks *hooksP); /* <> */
42+
}
43+
44+
#ifdef AE_OS_WIN
45+
BOOL __stdcall LibMain(HANDLE hInstance, DWORD fdwReason, LPVOID lpReserved);
46+
#endif
47+
48+
#endif //EMP_H

0 commit comments

Comments
 (0)