|
|
|||||||
| Home | Register | Downloads | FAQ | Members List | Calendar | Arcade | Mark Forums Read |
» Less advertising throughout
» Post and participate in discussions
» Network with other forum members
» Free private messaging
![]() |
|
|
Thread Tools | Display Modes |
|
|
#21 |
|
Registered User
![]() ![]() ![]() ![]() Join Date: Apr 2007
Location: indiana
Posts: 694
|
hey, huffman encoding assignment. yay. Code:
#include <iostream>
#include <fstream>
#include <queue>
#include <string>
#include <ostream>
#include <sstream>
#define ENCODE 1
#define DECODE 0
#define QUIT 2
using namespace std;
class Encoder
{
public:
//----------methods----------------
//constructor for the Encoder class
Encoder(){}
//DESTRUCTOR
~Encoder(){}
//the method used to encode a file into huffman's code
void encode(const char* inputName,const char* outputName)
{
FREQUENCY_NODE* huffmanTree;
priority_queue<FREQUENCY_NODE*,vector<FREQUENCY_NODE*>,node_compare > freqQueue;
int* frequencies;
//read the input file and store the frequencies of each char
frequencies = frequencyCounter(inputName);
//convert the array which is stores the frequencies to a min priority queue
freqQueue=convertArrayToQueue(frequencies);
//convert the min priority queue into a huffman tree
huffmanTree = huffman(freqQueue);
//write the characters of the input file into the output file after encoding them terminated by a line feed
printEncoding(huffmanTree,inputName,outputName);
//write the tree into an output file
ofstream output;
output.open(outputName,ios::app);
output<< '\n' + appendFreqs(frequencies);
output.flush();
output.close();
//clean up the allocated memory
cleanTree(huffmanTree);
delete frequencies;
}//encode
//a method to decode a huffman encoded file and then return it to an original encoding
void decode(const char* inputName,const char* outputName)
{
//create a tree from the input file
FREQUENCY_NODE* huffmanTree;
huffmanTree = huffmanFromFile(inputName);
//write the output file
writeDecoded(inputName,outputName,huffmanTree);
//clean up the memory
cleanTree(huffmanTree);
}
private:
//-----------struct def------------------
// a struct to represent the nodes of the B-Tree created by the Huffman algorithm
struct FREQUENCY_NODE{
int frequency;
unsigned char charValue ;
FREQUENCY_NODE* leftChild;
FREQUENCY_NODE* rightChild;
string toString()
{
string returnString(1,charValue);
returnString+=",";
stringstream s;
s << frequency;
returnString+=s.str();
returnString+=",";
return returnString;
}
};
//this is needed to prevent the compare of two nodes from comparing addresses instead of key values
struct node_compare : binary_function<FREQUENCY_NODE*,FREQUENCY_NODE*, bool>
{
bool operator()(const FREQUENCY_NODE* v1, const FREQUENCY_NODE* v2) const
{
return (v1->frequency > v2->frequency);
}
};
//-----------methods---------------------
//a function that populates an array from 0-'127' where the index is the int value of the corresponding character.
int* frequencyCounter(const char* inputName)
{
unsigned char currentChar=0;
int* frequencies = new int[256];
for(int i=0;i<256;i++)
{
frequencies[i]=0;
}
ifstream inputFile;
inputFile.open(inputName, ios::in);
//fill the array of the frequencies using the char's ascii values as the index of the array
while(inputFile.good())
{
currentChar=inputFile.get();
if(inputFile.good())
{
frequencies[currentChar]++;
}
}
inputFile.close();
return frequencies;
}//frequencyCounter()
//a function for creating a priority queue from the frequencies read from the input file
priority_queue<FREQUENCY_NODE*,vector<FREQUENCY_NODE*>,node_compare > convertArrayToQueue(int* input)
{
// create min priority queue
priority_queue<FREQUENCY_NODE*,vector<FREQUENCY_NODE*>,node_compare > frequency_queue;
// for all of the elements in frequencies[], if the value of the frequency is not equal to zero,
// create a frequency node and insert it into the queue keyed by frequency.
for(int i =0; i < 256;i++)
{
if(input[i]!=0)
{
FREQUENCY_NODE* newNode = new FREQUENCY_NODE;
newNode->charValue=i;
newNode->frequency=input[i];
newNode->leftChild=NULL;
newNode->rightChild=NULL;
frequency_queue.push(newNode);
}
}
return frequency_queue;
}//convertArrayToQueue()
//a function for creating a huffman's tree from a min priority queue
FREQUENCY_NODE* huffman(priority_queue<FREQUENCY_NODE*,vector<FREQUENCY_NODE*>,node_compare > inputQueue)
{
//while the queue has more than one element
while(inputQueue.size()>1)
{
// pop off 2 elements
// create a new node with those two elements as its children and with the sum of their frequencies as its own frequency
FREQUENCY_NODE* compositeNode = new FREQUENCY_NODE;
compositeNode->charValue='`';
compositeNode->leftChild=(inputQueue.top());
inputQueue.pop();
compositeNode->rightChild=(inputQueue.top());
inputQueue.pop();
(compositeNode->frequency)=((compositeNode->rightChild)->frequency+(compositeNode->leftChild)->frequency);
// push the new node back into the queue
inputQueue.push(compositeNode);
}
//return the final remaining node
return (inputQueue.top());
}//huffman()
//free all the memory in the huffman tree
void cleanTree(FREQUENCY_NODE* tree)
{
if(tree->leftChild == NULL && tree->rightChild == NULL)
{
delete tree;
}
else
{
cleanTree(tree->leftChild);
cleanTree(tree->rightChild);
delete tree;
}
}
//this method will print out the encoding of the input
void printEncoding(FREQUENCY_NODE* tree,const char* inputFile,const char* outputFile)
{
unsigned char currentChar;
string encoding = "";
ifstream input;
input.open(inputFile, ios::in);
ofstream output;
output.open(outputFile);
while(input.good())
{
//while the input still has more characters, use the recursive helper function to generate
//the encoding of the character.
currentChar=input.get();
if(input.good())
{
output<<generateEncoding(tree,currentChar,encoding);
}
}
input.close();
output.flush();
output.close();
}//printencoding()
// a recursive method to generate the encoding of a character
string generateEncoding(FREQUENCY_NODE* _tree, char currentChar, string encodingString)
{
if(_tree->leftChild==NULL && _tree->rightChild==NULL)
{
//if we are in a leaf node check for the character match
if(_tree->charValue==currentChar)
{
//if this isnt true, the character is not in this node, so we reset the string
return encodingString;
}
return "";
}
string leftValue;
string rightValue;
leftValue=generateEncoding(_tree->leftChild, currentChar,encodingString+'0');
rightValue=generateEncoding(_tree->rightChild, currentChar,encodingString+'1');
//check for which branch the character is in
if(!leftValue.empty())return leftValue;
if(!rightValue.empty())return rightValue;
return "";
}//generateEncoding()
//a function for traversing the tree and appending the characters and frequencies
string appendFreqs(int* freqs)
{
string returnString;
for(int i=0;i<256;i++)
{
if(freqs[i]!=0)
{
unsigned char currentChar = i;
returnString.push_back(i);
returnString.push_back(',');
stringstream s;
s<<freqs[i];
returnString+=s.str();
returnString.push_back(',');
}
}
return returnString;
}//appendFreqs()
//used to create a huffman tree from an input file
FREQUENCY_NODE* huffmanFromFile(const char* inputFile)
{
priority_queue<FREQUENCY_NODE*,vector<FREQUENCY_NODE*>,node_compare > freqQueue;
ifstream input(inputFile,ios::in);
unsigned char currentChar=0;
//scan to the beginning of the frequencies
input.ignore(100000,'\n');
//begin to generate nodes from the frequencies
while(input.good())
{
currentChar=input.get();
if(input.good())
{
string frequencyValue ="";
FREQUENCY_NODE* newNode = new FREQUENCY_NODE;
newNode->charValue=currentChar;
newNode->leftChild=NULL;
newNode->rightChild=NULL;
//skip the comma
input.ignore(1);
//read until the next comma
do
{
currentChar=input.get();
frequencyValue.push_back(currentChar);
}while(currentChar!=','&&input.good());
newNode->frequency=atoi(frequencyValue.c_str());
freqQueue.push(newNode);
}
}
input.close();
//return a huffman tree made from the queue
return huffman(freqQueue);
}//huffmanFromFile()
//this function will write to a file the result of the decoding
void writeDecoded(const char* inputFile,const char* outputFile, FREQUENCY_NODE* tree)
{
FREQUENCY_NODE* currentNode=tree;
ifstream input;
input.open(inputFile);
ofstream output;
output.open(outputFile);
char currentChar;
while(input.good())
{
currentChar=input.get();
if(input.good())
{
//read in 1's and 0's and follow the path until at a leaf node
if(currentChar=='0')
{
currentNode=(currentNode->leftChild);
}
else if(currentChar=='1')
{
currentNode=(currentNode->rightChild);
}
//if at a terminal node, spit out the char
if(currentNode->rightChild==NULL)
{
output.put((currentNode->charValue));
currentNode=tree;
}
}
}
input.close();
output.flush();
output.close();
}
};
int main()
{
Encoder encoder = Encoder();
int goodInput=0;
int encodeOrDecode=3;//random number here for initialization purposes
while(encodeOrDecode!=QUIT)
{
Encoder encoder = Encoder();
string inputFile="";
string outputFile="";
cout<<"Enter the name of the file you want to input.\n";
getline(cin,inputFile);
cout<<"Now enter the name of the file you wish to output to.\n";
getline(cin,outputFile);
while(goodInput==0)
{
string input="";
cout<<"Type a 0 if you want to decode a file and a 1 if you want to encode a file\n";
getline(cin,input);
encodeOrDecode = atoi(input.c_str());
if(encodeOrDecode==ENCODE||encodeOrDecode==DECODE || encodeOrDecode==QUIT)
{
goodInput=1;
}
}
if(encodeOrDecode==DECODE)
{
encoder.decode(inputFile.c_str(),outputFile.c_str());
}
else if(encodeOrDecode=ENCODE)
{
encoder.encode(inputFile.c_str(),outputFile.c_str());
}
goodInput=0;
}
}
|
|
|
|
| Advertisement | [Remove Advertisement] | ||
|
|
|
#22 | |
|
Level 9998
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Nov 2006
Location: Java
Posts: 9,377
|
Quote:
Code:
static void Main(string[] args) {
Console.WriteLine("1 + 2 = ?");
check((Console.ReadLine()).ToLower());
}
static void check(string a)
{
if (a != "y")
if (a == "3") Console.WriteLine("Correct, good job!");
else if (a == "n") Console.WriteLine("1 + 2 = ?");
else Console.WriteLine("Incorrect, try again!");
Console.WriteLine(n0 + " + " + n1 + " = ? (Type in '0' to quit)");
check((Console.ReadLine()).ToLower());
}
}
Fixed and... (hopefully) improved.Just for kicks... Code:
static void Main(string[] args) {
int n0 = 1;
int n1 = 2;
Console.WriteLine(n0 + " + " + n1 + " = ? (Type in '0' to quit)");
check(n0,n1,int.Parse(Console.ReadLine()));
}
static void check(int n0, int n1, int a)
{
if (a != 0)
if (a != (n0 + n1)) Console.WriteLine("Incorrect, try again!");
else Console.WriteLine("Correct, good job!");
n0++;
n1++;
Console.WriteLine(n0 + " + " + n1 + " = ? (Type in '0' to quit)");
check(n0,n1,int.Parse(Console.ReadLine()));
}
}
![]() Code:
static void Main(string[] args) {
string n = "";
while(n != "y") {
Console.WriteLine("1 + 2 = ?");
n = (Console.ReadLine()).ToLower();
if (n == "3") Console.WriteLine("Correct, good job!");
else if (n != "n") Console.WriteLine("Incorrect, try again!");
}
}
|
|
|
|
|
|
|
#23 | |
|
Crazy GFX coder
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Nov 2002
Location: Dominican Republic/Austria
Posts: 8,096
|
Quote:
__________________
![]() Current development tools: Visual C++.net, Visual C#.net Visual VB.net, Visual Webdeveloper.net Bloodshed Dev C++, Borland C++ Visual Basic 6 |
|
|
|
|
|
|
#24 |
|
Global Moderator
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jul 2001
Location: SC, USA
Posts: 7,231
|
Here's my OGL fragment program based N64 color combiner "emulator" written in VB.NET. Just a small but very important portion of my N64 graphics work. ![]() Code:
#Region "Color Combiner"
Private Sub SETCOMBINE(ByVal w0 As UInteger, ByVal w1 As UInteger)
If GLExtensions.GLFragProg Then
EnableCombiner = True
Dim ShaderCachePos As Integer = -1
For i As Integer = 0 To FragShaderCache.Length - 1
If (w0 = FragShaderCache(i).MUXS0) And (w1 = FragShaderCache(i).MUXS1) Then
ShaderCachePos = i
Exit For
End If
Next
If ShaderCachePos > -1 Then
Gl.glBindProgramARB(Gl.GL_FRAGMENT_PROGRAM_ARB, FragShaderCache(ShaderCachePos).FragShader)
Else
DecodeMUX(w0, w1, FragShaderCache, FragShaderCache.Length)
End If
Else
EnableCombiner = False
End If
End Sub
Private Sub SETFOGCOLOR(ByVal CMDDword() As Byte)
FogColor(0) = CMDDword(4) / 255
FogColor(1) = CMDDword(5) / 255
FogColor(2) = CMDDword(6) / 255
FogColor(3) = CMDDword(7) / 255
End Sub
Private Sub SETBLENDCOLOR(ByVal CMDDword() As Byte)
BlendColor(0) = CMDDword(4) / 255
BlendColor(1) = CMDDword(5) / 255
BlendColor(2) = CMDDword(6) / 255
BlendColor(3) = CMDDword(7) / 255
End Sub
Private Sub SETENVCOLOR(ByVal CMDDword() As Byte)
EnvironmentColor(0) = CMDDword(4) / 255
EnvironmentColor(1) = CMDDword(5) / 255
EnvironmentColor(2) = CMDDword(6) / 255
EnvironmentColor(3) = CMDDword(7) / 255
End Sub
Private Sub SETPRIMCOLOR(ByVal CMDDword() As Byte)
PrimColor(0) = CMDDword(4) / 255
PrimColor(1) = CMDDword(5) / 255
PrimColor(2) = CMDDword(6) / 255
PrimColor(3) = CMDDword(7) / 255
End Sub
Public Sub PrecompileMUXS(ByVal MUXLIST1() As UInteger, ByVal MUXLIST2() As UInteger)
If MUXLIST1.Length = MUXLIST2.Length Then
For i As Integer = 0 To MUXLIST1.Length - 1
DecodeMUX(MUXLIST1(i), MUXLIST2(i), FragShaderCache, i)
Next
End If
PrecompiledCombiner = True
End Sub
Public Sub DecodeMUX(ByVal MUXS0 As UInteger, ByVal MUXS1 As UInteger, ByRef Cache() As ShaderCache, ByVal CacheEntry As Integer)
ColorA(0) = (MUXS0 >> 20) And &HF
ColorB(0) = (MUXS1 >> 28) And &HF
ColorC(0) = (MUXS0 >> 15) And &H1F
ColorD(0) = (MUXS1 >> 15) And &H7
AlphaA(0) = (MUXS0 >> 12) And &H7
AlphaB(0) = (MUXS1 >> 12) And &H7
AlphaC(0) = (MUXS0 >> 9) And &H7
AlphaD(0) = (MUXS1 >> 9) And &H7
ColorA(1) = (MUXS0 >> 5) And &HF
ColorB(1) = (MUXS1 >> 24) And &HF
ColorC(1) = (MUXS0 >> 0) And &H1F
ColorD(1) = (MUXS1 >> 6) And &H7
AlphaA(1) = (MUXS1 >> 21) And &H7
AlphaB(1) = (MUXS1 >> 3) And &H7
AlphaC(1) = (MUXS1 >> 18) And &H7
AlphaD(1) = (MUXS1 >> 0) And &H7
If GLExtensions.GLFragProg Then
ReDim Preserve Cache(CacheEntry)
Cache(CacheEntry).MUXS0 = MUXS0
Cache(CacheEntry).MUXS1 = MUXS1
CreateShader(2, Cache(CacheEntry).FragShader)
Else
'TODO - At least limited color combiner emulation without using pixel shaders *shrug*
End If
End Sub
Private Sub CreateShader(ByVal Cycles As Integer, ByRef prog As Int32)
Dim ShaderLines As String = "!!ARBfp1.0" & Environment.NewLine & Environment.NewLine & _
"TEMP CCReg;" & Environment.NewLine & _
"TEMP ACReg;" & Environment.NewLine & Environment.NewLine & _
"TEMP CCRegister_0;" & Environment.NewLine & _
"TEMP CCRegister_1;" & Environment.NewLine & _
"TEMP ACRegister_0;" & Environment.NewLine & _
"TEMP ACRegister_1;" & Environment.NewLine & _
"TEMP Texel0;" & Environment.NewLine & _
"TEMP Texel1;" & Environment.NewLine & _
"PARAM EnvColor = program.env[0];" & Environment.NewLine & _
"PARAM PrimColor = program.env[1];" & Environment.NewLine & _
"ATTRIB Shade = fragment.color.primary;" & Environment.NewLine & Environment.NewLine & _
"OUTPUT FinalColor = result.color;" & Environment.NewLine & Environment.NewLine & _
"TEX Texel0, fragment.texcoord[0], texture[0], 2D;" & Environment.NewLine & _
"TEX Texel1, fragment.texcoord[1], texture[1], 2D;" & Environment.NewLine & Environment.NewLine
For i As Integer = 0 To Cycles - 1
Select Case ColorA(i)
Case RDP.G_CCMUX_COMBINED
ShaderLines += "MOV CCRegister_0.rgb, CCReg;" & Environment.NewLine
Case RDP.G_CCMUX_TEXEL0
ShaderLines += "MOV CCRegister_0.rgb, Texel0;" & Environment.NewLine
Case RDP.G_CCMUX_TEXEL1
ShaderLines += "MOV CCRegister_0.rgb, Texel1;" & Environment.NewLine
Case RDP.G_CCMUX_PRIMITIVE
ShaderLines += "MOV CCRegister_0.rgb, PrimColor;" & Environment.NewLine
Case RDP.G_CCMUX_SHADE
ShaderLines += "MOV CCRegister_0.rgb, Shade;" & Environment.NewLine
Case RDP.G_CCMUX_ENVIRONMENT
ShaderLines += "MOV CCRegister_0.rgb, EnvColor;" & Environment.NewLine
Case RDP.G_CCMUX_1
ShaderLines += "MOV CCRegister_0.rgb, {1.0,1.0,1.0,1.0};" & Environment.NewLine
Case RDP.G_CCMUX_COMBINED_ALPHA
ShaderLines += "MOV CCRegister_0.rgb, CCReg.a;" & Environment.NewLine
Case RDP.G_CCMUX_TEXEL0_ALPHA
ShaderLines += "MOV CCRegister_0.rgb, Texel0.a;" & Environment.NewLine
Case RDP.G_CCMUX_TEXEL1_ALPHA
ShaderLines += "MOV CCRegister_0.rgb, Texel1.a;" & Environment.NewLine
Case RDP.G_CCMUX_PRIMITIVE_ALPHA
ShaderLines += "MOV CCRegister_0.rgb, PrimColor.a;" & Environment.NewLine
Case RDP.G_CCMUX_SHADE_ALPHA
ShaderLines += "MOV CCRegister_0.rgb, Shade.a;" & Environment.NewLine
Case RDP.G_CCMUX_ENV_ALPHA
ShaderLines += "MOV CCRegister_0.rgb, EnvColor.a;" & Environment.NewLine
Case RDP.G_CCMUX_LOD_FRACTION
ShaderLines += "MOV CCRegister_0.rgb, {0.0,0.0,0.0,0.0};" & Environment.NewLine
Case RDP.G_CCMUX_PRIM_LOD_FRAC
ShaderLines += "MOV CCRegister_0.rgb, {0.0,0.0,0.0,0.0};" & Environment.NewLine
Case 15
ShaderLines += "MOV CCRegister_0.rgb, {0.0,0.0,0.0,0.0};" & Environment.NewLine
Case Else
ShaderLines += "MOV CCRegister_0.rgb, {0.0,0.0,0.0,0.0};" & Environment.NewLine
End Select
Select Case ColorB(i)
Case RDP.G_CCMUX_COMBINED
ShaderLines += "MOV CCRegister_1.rgb, CCReg;" & Environment.NewLine
Case RDP.G_CCMUX_TEXEL0
ShaderLines += "MOV CCRegister_1.rgb, Texel0;" & Environment.NewLine
Case RDP.G_CCMUX_TEXEL1
ShaderLines += "MOV CCRegister_1.rgb, Texel1;" & Environment.NewLine
Case RDP.G_CCMUX_PRIMITIVE
ShaderLines += "MOV CCRegister_1.rgb, PrimColor;" & Environment.NewLine
Case RDP.G_CCMUX_SHADE
ShaderLines += "MOV CCRegister_1.rgb, Shade;" & Environment.NewLine
Case RDP.G_CCMUX_ENVIRONMENT
ShaderLines += "MOV CCRegister_1.rgb, EnvColor;" & Environment.NewLine
Case RDP.G_CCMUX_1
ShaderLines += "MOV CCRegister_1.rgb, {1.0,1.0,1.0,1.0};" & Environment.NewLine
Case RDP.G_CCMUX_COMBINED_ALPHA
ShaderLines += "MOV CCRegister_1.rgb, CCReg.a;" & Environment.NewLine
Case RDP.G_CCMUX_TEXEL0_ALPHA
ShaderLines += "MOV CCRegister_1.rgb, Texel0.a;" & Environment.NewLine
Case RDP.G_CCMUX_TEXEL1_ALPHA
ShaderLines += "MOV CCRegister_1.rgb, Texel1.a;" & Environment.NewLine
Case RDP.G_CCMUX_PRIMITIVE_ALPHA
ShaderLines += "MOV CCRegister_1.rgb, PrimColor.a;" & Environment.NewLine
Case RDP.G_CCMUX_SHADE_ALPHA
ShaderLines += "MOV CCRegister_1.rgb, Shade.a;" & Environment.NewLine
Case RDP.G_CCMUX_ENV_ALPHA
ShaderLines += "MOV CCRegister_1.rgb, EnvColor.a;" & Environment.NewLine
Case Else
ShaderLines += "MOV CCRegister_1.rgb, {0.0,0.0,0.0,0.0};" & Environment.NewLine
End Select
ShaderLines += "SUB CCRegister_0, CCRegister_0, CCRegister_1;" & Environment.NewLine & Environment.NewLine
Select Case ColorC(i)
Case RDP.G_CCMUX_COMBINED
ShaderLines += "MOV CCRegister_1.rgb, CCReg;" & Environment.NewLine
Case RDP.G_CCMUX_TEXEL0
ShaderLines += "MOV CCRegister_1.rgb, Texel0;" & Environment.NewLine
Case RDP.G_CCMUX_TEXEL1
ShaderLines += "MOV CCRegister_1.rgb, Texel1;" & Environment.NewLine
Case RDP.G_CCMUX_PRIMITIVE
ShaderLines += "MOV CCRegister_1.rgb, PrimColor;" & Environment.NewLine
Case RDP.G_CCMUX_SHADE
ShaderLines += "MOV CCRegister_1.rgb, Shade;" & Environment.NewLine
Case RDP.G_CCMUX_ENVIRONMENT
ShaderLines += "MOV CCRegister_1.rgb, EnvColor;" & Environment.NewLine
Case RDP.G_CCMUX_1
ShaderLines += "MOV CCRegister_1.rgb, {1.0,1.0,1.0,1.0};" & Environment.NewLine
Case RDP.G_CCMUX_COMBINED_ALPHA
ShaderLines += "MOV CCRegister_1.rgb, CCReg.a;" & Environment.NewLine
Case RDP.G_CCMUX_TEXEL0_ALPHA
ShaderLines += "MOV CCRegister_1.rgb, Texel0.a;" & Environment.NewLine
Case RDP.G_CCMUX_TEXEL1_ALPHA
ShaderLines += "MOV CCRegister_1.rgb, Texel1.a;" & Environment.NewLine
Case RDP.G_CCMUX_PRIMITIVE_ALPHA
ShaderLines += "MOV CCRegister_1.rgb, PrimColor.a;" & Environment.NewLine
Case RDP.G_CCMUX_SHADE_ALPHA
ShaderLines += "MOV CCRegister_1.rgb, Shade.a;" & Environment.NewLine
Case RDP.G_CCMUX_ENV_ALPHA
ShaderLines += "MOV CCRegister_1.rgb, EnvColor.a;" & Environment.NewLine
Case RDP.G_CCMUX_K5
ShaderLines += "MOV CCRegister_1.rgb, {1.0,1.0,1.0,1.0};" & Environment.NewLine
Case RDP.G_CCMUX_0
ShaderLines += "MOV CCRegister_1.rgb, {0.0,0.0,0.0,0.0};" & Environment.NewLine
Case Else
ShaderLines += "MOV CCRegister_1.rgb, {0.0,0.0,0.0,0.0};" & Environment.NewLine
End Select
ShaderLines += "MUL CCRegister_0, CCRegister_0, CCRegister_1;" & Environment.NewLine & Environment.NewLine
Select Case ColorD(i)
Case RDP.G_CCMUX_COMBINED
ShaderLines += "MOV CCRegister_1.rgb, CCReg;" & Environment.NewLine
Case RDP.G_CCMUX_TEXEL0
ShaderLines += "MOV CCRegister_1.rgb, Texel0;" & Environment.NewLine
Case RDP.G_CCMUX_TEXEL1
ShaderLines += "MOV CCRegister_1.rgb, Texel1;" & Environment.NewLine
Case RDP.G_CCMUX_PRIMITIVE
ShaderLines += "MOV CCRegister_1.rgb, PrimColor;" & Environment.NewLine
Case RDP.G_CCMUX_SHADE
ShaderLines += "MOV CCRegister_1.rgb, Shade;" & Environment.NewLine
Case RDP.G_CCMUX_ENVIRONMENT
ShaderLines += "MOV CCRegister_1.rgb, EnvColor;" & Environment.NewLine
Case RDP.G_CCMUX_1
ShaderLines += "MOV CCRegister_1.rgb, {1.0,1.0,1.0,1.0};" & Environment.NewLine
Case Else
ShaderLines += "MOV CCRegister_1.rgb, {0.0,0.0,0.0,0.0};" & Environment.NewLine
End Select
ShaderLines += "ADD CCRegister_0, CCRegister_0, CCRegister_1;" & Environment.NewLine & Environment.NewLine
Select Case AlphaA(i)
Case RDP.G_ACMUX_COMBINED
ShaderLines += "MOV ACRegister_0.a, ACReg;" & Environment.NewLine
Case RDP.G_ACMUX_TEXEL0
ShaderLines += "MOV ACRegister_0.a, Texel0;" & Environment.NewLine
Case RDP.G_ACMUX_TEXEL1
ShaderLines += "MOV ACRegister_0.a, Texel1;" & Environment.NewLine
Case RDP.G_ACMUX_PRIMITIVE
ShaderLines += "MOV ACRegister_0.a, PrimColor;" & Environment.NewLine
Case RDP.G_ACMUX_SHADE
ShaderLines += "MOV ACRegister_0.a, Shade;" & Environment.NewLine
Case RDP.G_ACMUX_ENVIRONMENT
ShaderLines += "MOV ACRegister_0.a, EnvColor;" & Environment.NewLine
Case RDP.G_ACMUX_1
ShaderLines += "MOV ACRegister_0.a, {1.0,1.0,1.0,1.0};" & Environment.NewLine
Case RDP.G_ACMUX_0
ShaderLines += "MOV ACRegister_0.a, {0.0,0.0,0.0,0.0};" & Environment.NewLine
Case Else
ShaderLines += "MOV ACRegister_0.a, {0.0,0.0,0.0,0.0};" & Environment.NewLine
End Select
Select Case AlphaB(i)
Case RDP.G_ACMUX_COMBINED
ShaderLines += "MOV ACRegister_1.a, ACReg.a;" & Environment.NewLine
Case RDP.G_ACMUX_TEXEL0
ShaderLines += "MOV ACRegister_1.a, Texel0.a;" & Environment.NewLine
Case RDP.G_ACMUX_TEXEL1
ShaderLines += "MOV ACRegister_1.a, Texel1.a;" & Environment.NewLine
Case RDP.G_ACMUX_PRIMITIVE
ShaderLines += "MOV ACRegister_1.a, PrimColor.a;" & Environment.NewLine
Case RDP.G_ACMUX_SHADE
ShaderLines += "MOV ACRegister_1.a, Shade.a;" & Environment.NewLine
Case RDP.G_ACMUX_ENVIRONMENT
ShaderLines += "MOV ACRegister_1.a, EnvColor.a;" & Environment.NewLine
Case RDP.G_ACMUX_1
ShaderLines += "MOV ACRegister_1.a, {1.0,1.0,1.0,1.0};" & Environment.NewLine
Case RDP.G_ACMUX_0
ShaderLines += "MOV ACRegister_1.a, {0.0,0.0,0.0,0.0};" & Environment.NewLine
Case Else
ShaderLines += "MOV ACRegister_1.a, {0.0,0.0,0.0,0.0};" & Environment.NewLine
End Select
ShaderLines += "SUB ACRegister_0.a, ACRegister_0.a, ACRegister_1.a;" & Environment.NewLine
Select Case AlphaC(i)
Case RDP.G_ACMUX_COMBINED
ShaderLines += "MOV ACRegister_1.a, ACReg.a;" & Environment.NewLine
Case RDP.G_ACMUX_TEXEL0
ShaderLines += "MOV ACRegister_1.a, Texel0.a;" & Environment.NewLine
Case RDP.G_ACMUX_TEXEL1
ShaderLines += "MOV ACRegister_1.a, Texel1.a;" & Environment.NewLine
Case RDP.G_ACMUX_PRIMITIVE
ShaderLines += "MOV ACRegister_1.a, PrimColor.a;" & Environment.NewLine
Case RDP.G_ACMUX_SHADE
ShaderLines += "MOV ACRegister_1.a, Shade.a;" & Environment.NewLine
Case RDP.G_ACMUX_ENVIRONMENT
ShaderLines += "MOV ACRegister_1.a, EnvColor.a;" & Environment.NewLine
Case RDP.G_ACMUX_1
ShaderLines += "MOV ACRegister_1.a, {1.0,1.0,1.0,1.0};" & Environment.NewLine
Case RDP.G_ACMUX_0
ShaderLines += "MOV ACRegister_1.a, {0.0,0.0,0.0,0.0};" & Environment.NewLine
Case Else
ShaderLines += "MOV ACRegister_1.a, {0.0,0.0,0.0,0.0};" & Environment.NewLine
End Select
ShaderLines += "MUL ACRegister_0.a, ACRegister_0.a, ACRegister_1.a;" & Environment.NewLine
Select Case AlphaD(i)
Case RDP.G_ACMUX_COMBINED
ShaderLines += "MOV ACRegister_1.a, ACReg.a;" & Environment.NewLine
Case RDP.G_ACMUX_TEXEL0
ShaderLines += "MOV ACRegister_1.a, Texel0.a;" & Environment.NewLine
Case RDP.G_ACMUX_TEXEL1
ShaderLines += "MOV ACRegister_1.a, Texel1.a;" & Environment.NewLine
Case RDP.G_ACMUX_PRIMITIVE
ShaderLines += "MOV ACRegister_1.a, PrimColor.a;" & Environment.NewLine
Case RDP.G_ACMUX_SHADE
ShaderLines += "MOV ACRegister_1.a, Shade.a;" & Environment.NewLine
Case RDP.G_ACMUX_ENVIRONMENT
ShaderLines += "MOV ACRegister_1.a, EnvColor.a;" & Environment.NewLine
Case RDP.G_ACMUX_1
ShaderLines += "MOV ACRegister_1.a, {1.0,1.0,1.0,1.0};" & Environment.NewLine
Case RDP.G_ACMUX_0
ShaderLines += "MOV ACRegister_1.a, {0.0,0.0,0.0,0.0};" & Environment.NewLine
Case Else
ShaderLines += "MOV ACRegister_1.a, {0.0,0.0,0.0,0.0};" & Environment.NewLine
End Select
ShaderLines += "ADD ACRegister_0.a, ACRegister_0.a, ACRegister_1.a;" & Environment.NewLine & Environment.NewLine
ShaderLines += "MOV CCReg.rgb, CCRegister_0;" & Environment.NewLine
ShaderLines += "MOV ACReg.a, ACRegister_0.a;" & Environment.NewLine
Next
ShaderLines += "MOV CCReg.a, ACReg.a;" & Environment.NewLine
ShaderLines += "MOV FinalColor, CCReg;" & Environment.NewLine
ShaderLines += "END" & Environment.NewLine
Dim program() As Byte = System.Text.Encoding.ASCII.GetBytes(ShaderLines)
Gl.glGenProgramsARB(1, prog)
Gl.glBindProgramARB(Gl.GL_FRAGMENT_PROGRAM_ARB, prog)
Gl.glProgramStringARB(Gl.GL_FRAGMENT_PROGRAM_ARB, Gl.GL_PROGRAM_FORMAT_ASCII_ARB, program.Length, program)
End Sub
#End Region
__________________
![]() Last edited by cooliscool; December 2nd, 2009 at 13:46.. |
|
|
|
|
|
#25 |
|
Crazy GFX coder
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Nov 2002
Location: Dominican Republic/Austria
Posts: 8,096
|
Nice code cooliscool! makes me remember my VB6 days hehehehehe.
__________________
![]() Current development tools: Visual C++.net, Visual C#.net Visual VB.net, Visual Webdeveloper.net Bloodshed Dev C++, Borland C++ Visual Basic 6 |
|
|
|
|
|
#26 | |
|
Global Moderator
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jul 2001
Location: SC, USA
Posts: 7,231
|
Quote:
Too many people, but not all, have an elitist point of view when it comes to language choice, which I've found to be completely unfounded in most cases. The only problem I have is the obvious platform restrictions, but it's not much of a loss when most computer users either run Windows alone or multiboot with their OS of choice. Also can't forget how incredibly well designed Microsoft's IDEs and debuggers are. Nothing like them.
__________________
![]() Last edited by cooliscool; December 2nd, 2009 at 16:01.. |
|
|
|
|
|
|
#27 | |||
|
Crazy GFX coder
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Nov 2002
Location: Dominican Republic/Austria
Posts: 8,096
|
Quote:
iīve seen your tools and they are really cool.. in my case i avoid the VB syntax(even liking VB6).. somehow i donīt like it(its just a taste thing ) eventhough iīve toyed with VB.net and its pretty awesome to say the least one thing i really like about VB.net against VB6... youīre not allowed anymore to declare a variable as "Optional"(as far as i know) ![]() Quote:
but thanks God time make us wiser .Quote:
last but not least i consider myself a defender of C/C++, C# and even VB but i choosed not to promote any silly idealism like the one i mentioned above .
__________________
![]() Current development tools: Visual C++.net, Visual C#.net Visual VB.net, Visual Webdeveloper.net Bloodshed Dev C++, Borland C++ Visual Basic 6 Last edited by @ruantec; December 2nd, 2009 at 16:58.. |
|||
|
|
|
|
|
#28 | |
|
Global Moderator
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jul 2001
Location: SC, USA
Posts: 7,231
|
Quote:
__________________
![]() |
|
|
|
|
|
|
#29 | |
|
Registered User
![]() ![]() ![]() ![]() Join Date: Apr 2007
Location: indiana
Posts: 694
|
Quote:
PayScale - VB.Net Skill Salary, Average Salaries PayScale - C# Skill Salary, Average Salaries I'm not saying one way or another whether or not I agree with the stigma against VB, but the fact is that it does exist. Given that it does exist, it is a good thing to keep in mind when choosing which skill set you wish to develop. |
|
|
|
|
|
|
#30 |
|
Global Moderator
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jul 2001
Location: SC, USA
Posts: 7,231
|
I was referring to personal preference when it comes to my own projects; I do know C#/C++ quite well, but I prefer VB.
__________________
![]() |
|
|
|
|
|
#31 |
|
Crazy GFX coder
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Nov 2002
Location: Dominican Republic/Austria
Posts: 8,096
|
it is me or is Java the better payed job followed by C#? anyways money isnīt everything and he was refering to personal preferences so a higher salary is totally irrelevant in this case. ![]() ![]() ![]() ![]()
__________________
![]() Current development tools: Visual C++.net, Visual C#.net Visual VB.net, Visual Webdeveloper.net Bloodshed Dev C++, Borland C++ Visual Basic 6 Last edited by @ruantec; December 2nd, 2009 at 19:59.. |
|
|
|
|
|
#32 | |
|
You're already dead...
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Sep 2007
Location: Planet Vegeta
Posts: 5,385
|
Quote:
java/c#/c/c++ are all very similar syntax so coding with them feels kindoff the same (especially with java&c# or c&c++). so i always 'remember' the basic syntax for those languages, but vb is very different compared to those, so it takes more effort to remember. since vb is intended for rapid application development, yet i'm forgetting the language, it loses its purpose. so for me i think i'm abandoning it for the most part. if for some reason i have to use it again, it shouldn't be too difficult to learn though.
__________________
"It was, of course, a lie what you read about my religious convictions, a lie which is being systematically repeated. I do not believe in a personal God and I have never denied this but have expressed it clearly. If something is in me which can be called religious then it is the unbounded admiration for the structure of the world so far as our science can reveal it." - Albert Einstein check out my blog ![]() |
|
|
|
|
|
|
#33 |
|
Knowledge is the solution
![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Dec 2002
Location: Pittsburgh, US. Previously in Mexico City
Posts: 7,160
|
Then again you might prefer you use python, which is intended for RAD as well and is quite similar to the likes of C++/Java.
__________________
|
|
|
|
|
|
#34 |
|
Crazy GFX coder
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Nov 2002
Location: Dominican Republic/Austria
Posts: 8,096
|
Cooliscool... i Just forgot to mention on my other post that VB.Net has advantages over VB6.. the only advantage of VB6 i can remember so far is that it doesnīt require the .net framework ![]() VB.Net isnīt that bad but quite the opposite as its more powerfull than older versions... just as i mentioned before they removed the posibility to declare a variable as "Optional" which to me was a nonsense.. also they added better stuff i wonīt mention here to keep my post as small as possible . another advantage of VB.Net over VB6 is that you can create intranet apps quite easy, Silverlight and WPF applications not to mention you have a very powerfull framework on your hands so i consider VB.Net is undertimated by many coders probably..anyways such confusions seems to be common nowdays as VB isnīt the only one... most people when they hear about C# the first thing that comes to there minds is "Java" but in reality that isnīt right at all.. the reason for that is because C# original name wasnīt Java++ or something like that.. what they forget is that its original codename was C+++ as it was developed as the sucessor of C++ and not Java. the addition of some java features makes sense as they are very usefull in many cases. eventhough C# main concept is based in no other than C++. so again the VB confusion isnīt the only one
__________________
![]() Current development tools: Visual C++.net, Visual C#.net Visual VB.net, Visual Webdeveloper.net Bloodshed Dev C++, Borland C++ Visual Basic 6 Last edited by @ruantec; December 2nd, 2009 at 21:52.. |
|
|
|
|
|
#35 | ||
|
You're already dead...
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Sep 2007
Location: Planet Vegeta
Posts: 5,385
|
Quote:
definining functions is a different syntax, as well as no ';' to denote end of statements (so i assume its line based, which i don't like). and a bunch of other syntax differences... c# i think is going to do as my RAD language. its annoying type strictness and other limitations makes for more code than i would like though... Quote:
one of the creators of java even called c# a java imitation. the concept and design for c# was highly influenced by java, its undeniable.
__________________
"It was, of course, a lie what you read about my religious convictions, a lie which is being systematically repeated. I do not believe in a personal God and I have never denied this but have expressed it clearly. If something is in me which can be called religious then it is the unbounded admiration for the structure of the world so far as our science can reveal it." - Albert Einstein check out my blog ![]() Last edited by cottonvibes; December 2nd, 2009 at 21:57.. Reason: Automerged Doublepost |
||
|
|
|
|
|
#36 | ||
|
Crazy GFX coder
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Nov 2002
Location: Dominican Republic/Austria
Posts: 8,096
|
Quote:
and if you use the intellisence wisely you will end writing your code faster and sometimes you donīt even have to write them at all(use the spacebar). while in C++ i may need slightly lower lines of code i still have an annoying intellisence that doesnīt even work as good as the C# one and therefore even needing slightly more code in C# in some areas at the end am still faster.Quote:
__________________
![]() Current development tools: Visual C++.net, Visual C#.net Visual VB.net, Visual Webdeveloper.net Bloodshed Dev C++, Borland C++ Visual Basic 6 Last edited by @ruantec; December 2nd, 2009 at 22:54.. |
||
|
|
|
|
|
#37 | |
|
Registered User
![]() ![]() ![]() ![]() Join Date: Apr 2007
Location: indiana
Posts: 694
|
Quote:
Couldn't have said it better myself. Writing good code is completely independent of the language choice; I think this is the most important point. I was just trying to say that, in general, people may have a leaning towards doing projects in c# because working on projects is in general a two-fold endeavor. People usually want to create some sort of meaningful application and they want to better learn a language that is relevant to modern software development. Therefore, it stands to reason there would be more projects being developed using c# than vb.net just for the reason that they want their learned skills to be more highly valued by potential employers. |
|
|
|
|
|
|
#38 | ||
|
You're already dead...
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Sep 2007
Location: Planet Vegeta
Posts: 5,385
|
Quote:
good code can mean different things depending on the coder (fastest code, cleanest code, simplest code, smart-code, code with less-overhead, etc...) but for the sake of not getting into another programming debate, i mostly agree. i would substitute 'mostly' or 'generally' instead of 'completely' from your statement though. Quote:
but i dislike 'longer' code, and almost always try and go for shorter more-compact code. intellisense won't help with that; instead its mostly restricted on how 'strict' the language is.
__________________
"It was, of course, a lie what you read about my religious convictions, a lie which is being systematically repeated. I do not believe in a personal God and I have never denied this but have expressed it clearly. If something is in me which can be called religious then it is the unbounded admiration for the structure of the world so far as our science can reveal it." - Albert Einstein check out my blog ![]() Last edited by cottonvibes; December 2nd, 2009 at 22:50.. Reason: Automerged Doublepost |
||
|
|
|
|
|
#39 | |
|
Crazy GFX coder
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Nov 2002
Location: Dominican Republic/Austria
Posts: 8,096
|
Quote:
of course thatīs not always true.
__________________
![]() Current development tools: Visual C++.net, Visual C#.net Visual VB.net, Visual Webdeveloper.net Bloodshed Dev C++, Borland C++ Visual Basic 6 |
|
|
|
|
|
|
#40 | |
|
Knowledge is the solution
![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Dec 2002
Location: Pittsburgh, US. Previously in Mexico City
Posts: 7,160
|
Quote:
Code:
int x = (++k < t & n) ? 3 : 8 * (n++ < 3);
__________________
|
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|