How do I get input from keybord on a C# windows form, I am coding the best 2d shooter on a windows form beacuaze I am coold now
Is there any way to make shadow_control apply to specific areas, like how color_correction works?
[QUOTE=DestWa;33689227]How do I get input from keybord on a C# windows form, I am coding the best 2d shooter on a windows form beacuaze I am coold now[/QUOTE]
If you have XNA installed try including this at the top
[code]using Microsoft.Xna.Framework.Input;[/code]
And us XNA's input methods.
Not sure how well this would work though.
[QUOTE=Capsup;33688308]Hey Richy, I'm trying to get textures to work myself, and see that your code does about the same as mine do. I believe mine is setup correct, but the textures are still black. Could I get to see your shader that you use with that code?[/QUOTE]
sure:
[cpp]#version 120
varying vec2 uv;
uniform sampler2D myTexture;
void main(){
gl_FragColor = texture2D( myTexture, uv ).rgba;
}
[/cpp]
the ".rgba" at the end isn't necessary, although it probably gets optimized away anyways.
I was wondering if anyone knows how to cut a texture and put it into a vertex in open gl. I tried whats below but all it does is scale the texture. I would like a texture be cut based on the vertexs. So like i have a texture that is 128x128 but i want to only draw whats at 8x8-16x16 or something like that.
[CODE]glBegin(GL_QUADS);
{
int XP = 1;
int YP = 1;
int TH = 5;
int TW = 2;
if(!Stretch)
{
TH = Tex.Height;
TW = Tex.Width;
}
glTexCoord2f((int)XP,(int)YP);
glVertex2f(0,0);
glTexCoord2f((int)XP,(int)TH);
glVertex2f(0,height);
glTexCoord2f((int)TW,(int)TH);
glVertex2f(width,height);
glTexCoord2f((int)TW,(int)YP);
glVertex2f(width,0);
}
glEnd();[/CODE]
textures go from 0 to 1. So if you had a 128x128 texture and you only wanted the top left 64x64 part of it your texture coordinates would look something like:
<0, 0.5f>
<0, 0>
<0.5f, 0.5f>
<0.5f, 0>
It might be flipped or something, depends on your projection matrix. Just switch some of the texture coordinates around until it's right side up.
[editline]12th December 2011[/editline]
Another example, if you wanted the segment from (64, 64) to (96, 128):
<0.5f, 1>
<0.5f, 0.5f>
<0.75f, 0.5f>
<0.75f, 1>
[QUOTE=robmaister12;33695093]textures go from 0 to 1. So if you had a 128x128 texture and you only wanted the top left 64x64 part of it your texture coordinates would look something like:
<0, 0.5f>
<0, 0>
<0.5f, 0.5f>
<0.5f, 0>
It might be flipped or something, depends on your projection matrix. Just switch some of the texture coordinates around until it's right side up.
[editline]12th December 2011[/editline]
Another example, if you wanted the segment from (64, 64) to (96, 128):
<0.5f, 1>
<0.5f, 0.5f>
<0.75f, 0.5f>
<0.75f, 1>[/QUOTE]
thanks i figured it out about 10 minutes after posting this. I made a system that converted the size you wanted to split it into a fraction. Then thats the size it works perfectly. Thanks for the reply though.
Anyone know any really good tutorials for XNA, really starting from the ground up with 3d?
[QUOTE=Mr. Smartass;33696776]Anyone know any really good tutorials for XNA, really starting from the ground up with 3d?[/QUOTE]
[url]http://www.riemers.net/[/url]
They were written for 3.1 but it shouldn't be hard to get it to work for 4.0.
[QUOTE=Jacen;33696972][url]http://www.riemers.net/[/url]
They were written for 3.1 but it shouldn't be hard to get it to work for 4.0.[/QUOTE]
If you scroll down to the 'Related Forum Posts' thing, there's XNA 4.0 specific fixes.
However some of the later tutorials about water don't apply anymore afaik.
[QUOTE=Jacen;33696972][url]http://www.riemers.net/[/url]
They were written for 3.1 but it shouldn't be hard to get it to work for 4.0.[/QUOTE]
I've seen those and they're great, but they don't really teach much lower level stuff other than procedural stuff, which is hella too complicated for me to understand.
[QUOTE=Richy19;33691593]sure:
[cpp]#version 120
varying vec2 uv;
uniform sampler2D myTexture;
void main(){
gl_FragColor = texture2D( myTexture, uv ).rgba;
}
[/cpp][/QUOTE]
Okay yeah... That's the same as I already have. I wonder what the heck my problem is then. I do use VAO's compared to what you use though, and I'm pretty sure that it's all been setup correct. I've tried to extract the code from the opengl superbible 5, although they use that stupid GLtools library along with glut. I use pure opengl and c++ as I believe it's necessary to know what goes on in the back. Although it's very hard to find any code that uses pure opengl and does textures. :(
glGenTextures(1, &myTexture);
glBindTexture(GL_TEXTURE_2D, myTexture);
...set some settings/upload the texture...
glBindTexture(GL_TEXTURE_2D, 0);
later when you're drawing...
glUseProgram(myProgram);
...set uniforms, etc...
glBindTexture(GL_TEXTURE_2D, myTexture);
...load your vao, draw whatever it is you're drawing...
glBindTexture(GL_TEXTURE_2D, 0);
glUseProgram(0);
as long as you've bound your texture, the fragment shader will be able to pick up the texture and draw with it. IIRC VAOs don't store bound textures, but I haven't done much with VAOs, so I'm not really sure.
[QUOTE=robmaister12;33698201]glGenTextures(1, &myTexture);
glBindTexture(GL_TEXTURE_2D, myTexture);
...set some settings/upload the texture...
glBindTexture(GL_TEXTURE_2D, 0);
later when you're drawing...
glUseProgram(myProgram);
...set uniforms, etc...
glBindTexture(GL_TEXTURE_2D, myTexture);
...load your vao, draw whatever it is you're drawing...
glBindTexture(GL_TEXTURE_2D, 0);
glUseProgram(0);
as long as you've bound your texture, the fragment shader will be able to pick up the texture and draw with it. IIRC VAOs don't store bound textures, but I haven't done much with VAOs, so I'm not really sure.[/QUOTE]
Yep, that's exactly what I do.
Here, I decided to get the code:
Creating the shader:
[cpp]
FlatTextureShader = sm.LoadFromFileUL( sGlobalPath + "/content/shaders/flattexture/shader.fp", sGlobalPath + "/content/shaders/flatcolor/shader.vp" );
glBindAttribLocation( FlatTextureShader, 0, "in_Position" );
glBindAttribLocation( FlatTextureShader, 1, "in_Color" );
glBindAttribLocation( FlatTextureShader, 2, "in_TexCoord0" );
FlatTextureShader = sm.LinkProgram( FlatTextureShader );
FTSmvpMatrix = glGetUniformLocation( FlatTextureShader, "mvpMatrix" );
FTSTex = glGetUniformLocation( FlatTextureShader, "texture0" );
[/cpp]
Creating buffer data:
[url]http://pastebin.com/fp92ZKr6[/url]
Loading buffer data:
[cpp]
glGenTextures(1, &uiTextureID);
glBindTexture( GL_TEXTURE_2D, uiTextureID );
LoadTGATexture( std::string( sGlobalPath + "/content/textures/grass.tga" ).c_str(), GL_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE );
glBindTexture( GL_TEXTURE_2D, 0 );
glBindVertexArray( uiArrayID[1] );
glBindBuffer( GL_ARRAY_BUFFER, uiBufferID[2] );
glBufferData( GL_ARRAY_BUFFER, sizeof( GLfloat ) * vertexesterrain.size(), &vertexesterrain.front(), GL_STATIC_DRAW );
glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 0, 0 );
glEnableVertexAttribArray( 0 );
glBindBuffer( GL_ARRAY_BUFFER, uiBufferID[3] );
glBufferData( GL_ARRAY_BUFFER, sizeof( GLfloat ) * colorsterrain.size(), &colorsterrain.front(), GL_STATIC_DRAW );
glVertexAttribPointer( 1, 4, GL_FLOAT, GL_FALSE, 0, 0 );
glEnableVertexAttribArray( 1 );
glBindBuffer( GL_ARRAY_BUFFER, uiBufferID[4] );
glBufferData( GL_ARRAY_BUFFER, sizeof( GLfloat ) * texcoordsterrain.size(), &texcoordsterrain.front(), GL_STATIC_DRAW );
glVertexAttribPointer( 2, 2, GL_FLOAT, GL_FALSE, 0, 0 );
glEnableVertexAttribArray( 2 );
glBindVertexArray( 0 );
glBindBuffer( GL_ARRAY_BUFFER, 0 );
glBindBuffer( GL_ARRAY_BUFFER, 0 );
glBindBuffer( GL_ARRAY_BUFFER, 0 );
[/cpp]
The LoadTGATexture function:
[cpp]
bool LoadTGATexture(const char *szFileName, GLenum minFilter, GLenum magFilter, GLenum wrapMode)
{
const unsigned char* pBits;
TargaImage tga;
tga.load( szFileName );
pBits = tga.getImageData();
if(pBits == NULL)
return false;
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapMode);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapMode);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D( GL_TEXTURE_2D, 0, tga.getBitsPerPixel(), tga.getWidth(), tga.getHeight(), 0, tga.getType(), GL_UNSIGNED_BYTE, pBits );
if( minFilter == GL_LINEAR_MIPMAP_LINEAR || minFilter == GL_LINEAR_MIPMAP_NEAREST || minFilter == GL_NEAREST_MIPMAP_LINEAR || minFilter == GL_NEAREST_MIPMAP_NEAREST )
glGenerateMipmap(GL_TEXTURE_2D);
return true;
}
[/cpp]
The drawing:
[cpp]
glUseProgram( FlatTextureShader );
glUniformMatrix4fv(FTSmvpMatrix, 1, GL_FALSE, glm::value_ptr( mvp ) );
glUniform1i( FTSTex, 0 );
if( bEnableCull )
glEnable( GL_CULL_FACE );
if( bEnableDepthTesting )
glEnable( GL_DEPTH_TEST );
glBindVertexArray( uiArrayID[1] );
glActiveTexture( GL_TEXTURE0 );
glBindTexture( GL_TEXTURE_2D, uiTextureID );
glDrawArrays( GL_TRIANGLES, 0, 15360 );
glBindTexture( GL_TEXTURE_2D, 0 );
glActiveTexture( GL_TEXTURE0 );
glBindVertexArray( 0 );
glDisable( GL_CULL_FACE );
glDisable( GL_DEPTH_TEST );
glUseProgram( 0 );
[/cpp]
The shader:
[cpp]
#version 130
uniform mat4 mvpMatrix;
in vec3 in_Position;
in vec4 in_Color;
in vec2 in_TexCoord0;
out vec4 pass_color;
out vec2 pass_texCoord0;
void main(void)
{
pass_texCoord0 = in_TexCoord0;
pass_color = in_Color;
gl_Position = mvpMatrix * in_Position;
}
[/cpp]
[cpp]
#version 130
precision highp float;
uniform sampler2D texture0;
in vec4 pass_color;
in vec2 pass_texCoord0;
out vec4 out_Color;
void main(void) {
out_Color = pass_color * texture(texture0, pass_texCoord0.st);
}
[/cpp]
make sure you're calling glEnable(GL_TEXTURE_2D) somewhere before rendering, it has to be enabled before you can use it.
Also, unless you're loading 2+ textures per draw call, you don't need the glActiveTexture calls.
[QUOTE=robmaister12;33699038]make sure you're calling glEnable(GL_TEXTURE_2D) somewhere before rendering, it has to be enabled before you can use it.
Also, unless you're loading 2+ textures per draw call, you don't need the glActiveTexture calls.[/QUOTE]
So before the bindtexture call, yeah? I've tried that, but it didn't change anything so assumed I didn't have to. I can't really think of what else to try. glGetError reports no errors at all either.
[QUOTE=robmaister12;33698201]
glBindTexture(GL_TEXTURE_2D, 0);
glUseProgram(0);
[/QUOTE]
Is this really needed?all i have aftr drawing is:
glDisableVertexAttribArray(UVID);
glDisableVertexAttribArray(positionID);
[QUOTE=Richy19;33699287]Is this really needed?all i have aftr drawing is:
glDisableVertexAttribArray(UVID);
glDisableVertexAttribArray(positionID);[/QUOTE]
It's only needed as long as you do anything after the draw call in which you don't unbind.
Also im using
glBindTexture(GL_TEXTURE_2D, texturebuffer);
glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA, image->GetWidth(), image->GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, image->GetPixelsPtr() );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
with my textures but when they rotate they go ugly:
[IMG]http://i.imgur.com/KpsTm.png[/IMG]
What settings should i use?
Is there a way to have the console window and the graphical/game window in C# (xna) at the same time, I would like to use the console for easier debugging.
Actually I don't think glEnable(GL_TEXTURE_2D) is needed, that was for the fixed function pipeline.
As for your texture, try turning multisampling on (AA).
[QUOTE=Richy19;33699287]Is this really needed?all i have aftr drawing is:
glDisableVertexAttribArray(UVID);
glDisableVertexAttribArray(positionID);[/QUOTE]
That state is saved in the vao. It's unnecessary to disable (or re enable) attributes unless you're reusing the vao for something else with less attributes.
Actually i'm not sure if you're using vaos so this might not be relevant. I was reading code from something else.
Thomasfn is correct, you don't need to enable GL_TEXTURE_2D if you are using a shader.
Richy, you should use GL_LINEAR for the magnification filter. For minification generally you should use GL_LINEAR_MIPMAP_LINEAR which will require you to provide or generate mipmaps (glGenerateMipmap can do it for you). If you are just drawing rotated sprites in 2D you can get away with GL_LINEAR as your minification filter too.
[QUOTE=bean_xp;33700505]Thomasfn is correct, you don't need to enable GL_TEXTURE_2D if you are using a shader.
Richy, you should use GL_LINEAR for the magnification filter. For minification generally you should use GL_LINEAR_MIPMAP_LINEAR which will require you to provide or generate mipmaps (glGenerateMipmap can do it for you). If you are just drawing rotated sprites in 2D you can get away with GL_LINEAR as your minification filter too.[/QUOTE]
Isnt glGenerateMpmaps 3.x< ?
Im using 2.1
[QUOTE=Richy19;33700553]Isnt glGenerateMpmaps 3.x< ?
Im using 2.1[/QUOTE]
It is core in gl 3, but should be available as an extension otherwise. If not you can use glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); (before your call to glTexImage2D).
Im now using this:
[cpp]void Quad::SetImage(sf::Image *eImage)
{
image = eImage;
glBindTexture(GL_TEXTURE_2D, texturebuffer);
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA, image->GetWidth(), image->GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, image->GetPixelsPtr() );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
}[/cpp]
but i get weird lines around the image
[IMG]http://i.imgur.com/R9ONk.png[/IMG]
The lines around the edge of the quad should be solved by setting the texture to clamp to edge with:
[cpp]
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
[/cpp]
The black areas around the edge of the shape are a litte harder to solve because it's down to the contents of the texture. If you take a pixel on the shoulder as an example, the pixel above is it black with the alpha value of 0, so when the texture unit interpolates between the shoulder and the pixel above you're left with something half way between red and black with half alpha.
It can be solved by editing the colour around the edges of the image before you apply alpha. But you need an editor which can correctly export those pixels, I think you can do it in GIMP with alpha masks.
[QUOTE=bean_xp;33700849]The lines around the edge of the quad should be solved by setting the texture to clamp to edge with:
[cpp]
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
[/cpp]
The black areas around the edge of the shape are a litte harder to solve because it's down to the contents of the texture. If you take a pixel on the shoulder as an example, the pixel above is it black with the alpha value of 0, so when the texture unit interpolates between the shoulder and the pixel above you're left with something half way between red and black with half alpha.
It can be solved by editing the colour around the edges of the image before you apply alpha. But you need an editor which can correctly export those pixels, I think you can do it in GIMP with alpha masks.[/QUOTE]
this is the actual image:
[img]http://i.imgur.com/DDoYs.png[/img]
doesnt have any black areas around the sprite :S, not sure how you mean about gimp
Very basic question, learning C#
I want to do a for loop to quickly change the text property of multiple labels all marked label1 to label6, how would I go to work with this? I thought I could just do an integer with 1 to 6 and stick that behind the word label, but I don't know how to do it or if it's even possible, or if I should take a different approach and see if I can put the labels into an array or if they already are.
Here's the (obviously not working at all) code I tried
[code]for (int i = 1; i <= 7; i++) {
'label'+i.Text = menu.GetMenuItem();
}[/code]
Sorry, you need to Log In to post a reply to this thread.