|
Hi
When I do File_New -> Attach Image, the image file can be loaded into memory.
But when I do File_open, the image file can not be loaded into memory. I did following:
Gdiplus::Graphics gr(dc);
gr.SetPageUnit(Gdiplus::UnitPixel);
gr.DrawImage(pBmp, p, 3);
What is problem?
Thanks
|
|
|
|
|
I'm trying to create an emboss/bevelled effect on circles and rectangles using C# with GDI+. Here's an example of a circle created with a drawing program with the emboss effect enabled:
Circle[^]
What it looks like to me is that you have two circles. The top circle is smaller and centered on the larger circle below it. Also, there is no shading on the top circle. Below that you have a base, which looks like a circle with a gradient going from light to dark.
Combined they give the overall look of an embossed circle.
Here's a square:
Square[^]
It's a bit more complicated. It looks like the right and bottom corners are quite a bit darker than the left and top corners. That's easy enough to mimic, but there's also something going on with the corners that I'm not sure how to duplicate.
I'm looking for any pointers on doing these types of basic effects with C# and GDI+. I've done some googling, but the results are focused on applying these effects to existing images. Since I'm building primitive shapes from scratch, I figure there are probably easier ways.
modified on Monday, June 8, 2009 8:51 PM
|
|
|
|
|
You're basically trying to simulate a 3D object with the light source in the upper left of the picture. If you want the details, you might search for 3D lighting algorithms. BTW, the link to the picture of your square is broken.
"Republicans are the party that says government doesn't work and then they get elected and prove it." -- P.J. O'Rourke I'm a proud denizen of the Real Soapbox[ ^] ACCEPT NO SUBSTITUTES!!!
|
|
|
|
|
Tim Craig wrote: BTW, the link to the picture of your square is broken.
Thanks, and fixed.
|
|
|
|
|
Are you looking to create graphical controls on the fly? The gradient idea sounds reasonable. The corners probably aren't that critical if that is the application.
"Republicans are the party that says government doesn't work and then they get elected and prove it." -- P.J. O'Rourke I'm a proud denizen of the Real Soapbox[ ^] ACCEPT NO SUBSTITUTES!!!
|
|
|
|
|
Tim Craig wrote: Are you looking to create graphical controls on the fly? The gradient idea sounds reasonable. The corners probably aren't that critical if that is the application.
My goal is to create a widget set for Windows Forms (and maybe eventually WPF) made up of knobs, sliders, and quite a few other custom controls. I'm hoping there's a market for this sort of thing. At any rate, I've spent the past couple of years writing VST plugins. In this arena custom UI's are the rule, and I'd like to take the knowledge I've gained creating in creating them and applying that to a .NET custom control library.
Here's an example of a VST UI I created:
Super Filter[^]
It's completely bitmap based.
So I'm trying to get my GDI+ chops up to the point where I can recreate the same level of detail only "on the fly," as you put it. My goal would be a set of controls that are drawn with GDI+ rather than pre-rendered with bitmaps. For examples, say you have a knob control. It would be cool to give it a Bevel property that let you set how beveled the edges looked.
While I have a feel for what makes up an image like a knob, recreating that programmically is another matter. I'm trying to walk the line between getting enough knowledge to do the job and diving headlong into studying mathematically intensive graphics algorithms.
The gradient approach seems ok, but I think I need to tweak how the colors fade a bit instead of relying on the default linear setting. The square shape seems more challenging in that the corners look like they need special care.
Anyway, I didn't mean to write such a long post. But at least you have an idea where I'm coming from.
|
|
|
|
|
That's pretty. I used to work with software for controlling instruments but we never tried to replace the front panel. We were sitting on top trying to automate the process. I don't know what kind of market there is for these kinds of widgets but there is one. National Instruments has made a good business out of them with their other offerings.
As far as GDI+ goes, I wonder if you'll have any performance issues since as far as I know, it's still not hardware accelerated. Maybe going to something like OpenGL (or even Direct3D ) and doing it in full 3D might be faster since they are hardware accelerated? I know there are widgets done for OpenGL applications so there is a model. But then all the display is OpenGL.
"Republicans are the party that says government doesn't work and then they get elected and prove it." -- P.J. O'Rourke I'm a proud denizen of the Real Soapbox[ ^] ACCEPT NO SUBSTITUTES!!!
|
|
|
|
|
I have two threads running in my application , each having its own separate GLX Rendering contexts.
But these two threads share the same window(X window). At start only one thread renders its graphics into the window.
Everythings works fine till this point of time.
Later , this thread's rendering is stopped and new thread(second thread) is created with new rendering context.But this new
rendering context is also attached to the same window.
But when this second thread starts rendering , I see some flickering on the screen.
Can anybody tell me whats happening ?
|
|
|
|
|
Hi all,
I want to Watermark(Overlay) an existing video. I don't want to
capture a new Video . For that I m using DirectShowLib DxText Sample
Application(in C#) for VideoWatermarking on an existing video.
It works fine but it only display the video with watermark as a
preview on screen.
Now I need to save the watermarked video on the disk as a new file.
Video Watermarking is also possible with VMR9Compositor sample code. But same problem is also exist with these code. It Shows only preview.
How can I save the new Video with watermark?
Thanks in Advance
|
|
|
|
|
I am having trouble transforming my objects in world space. Its seemigly simple, but i've tried many thing i found online, and still i cant crack it.
Heres the code:
I have a created cube, and am trying to transform a position matrix just before rendering it.
<per>
D3DXMATRIXA16 matWorld;
D3DXMatrixTranslation(&matWorld,10.0f,10.0f,50.0f);
HR(gd3dDevice->SetTransform( D3DTS_WORLD, &matWorld ));
HR(gd3dDevice->SetStreamSource(0, SphereVertexBuffer, 0, sizeof(VertexPos)));
HR(gd3dDevice->SetIndices(SphereIndexBuffer));
HR(gd3dDevice->SetVertexDeclaration(VertexPos::Decl));
HR(gd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST,0,0,num_vertices,0,4*meridians*(parallels-1)));
</per>
The code looks legit to me, so maybe the problem is in some other part of the code, or somehow in the way i set up my world. The world is in right handed coordinate system, i doubt it, buy might this be a problem?
Also another question, when i change the world matrix, as i understand it, EVERYTHING drawn after this is moved right? So i may be moving the ground and everything along with my object? But then againt i can use my camera as reference, and still dont see any displacement!
Any ideas?
ps. I am also using effects(ID3DXEffect*), maybe i need to use its settransform?!
|
|
|
|
|
There are actually three transforms used when rendering an object. The three transform types are: D3DTS_WORLD, D3DTS_VIEW, and D3DTS_PROJECTION. I'm assuming that your D3DPRESENT_PARAMETERS are correct.
Also, there are numerous RenderState variables that generally have to be set before making your Draw calls. These are based on the values received when querying, the IDirect3D9 Interface (actually, your DIRECT3DDEVICE9). The following code is unmanaged C++, but should be clear.
LPDIRECT3DDEVICE9->GetDeviceCaps (&D3DCAPS9) ;
Typical RenderState settings are made like this:
LPDIRECT3DDEVICE9->SetRenderState (D3DRS_FILLMODE, D3DFILL_SOLID) ;
LPDIRECT3DDEVICE9->SetRenderState (D3DRS_LIGHTING, FALSE) ;
By the way, your sphere code is impressive,...I have to try it to see if it works correctly.
I'm assuming that you are calling these functions in your render loop.
LPDIRECT3DDEVICE9->BeginScene () ;
LPDIRECT3DDEVICE9->Clear (0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER ,
D3DCOLOR_XRGB (0, 0, 0), .0f, 0 ) ;
LPDIRECT3DDEVICE9->EndScene () ;
LPDIRECT3DDEVICE9->Present (NULL, NULL, NULL, NULL) ;
Also, you should read this: Fixed Function FVF Codes, MSDN[^], and, Flexible Vertex Format Constants[^]
Good luck,...
|
|
|
|
|
It's quite late now, and I have no idea why when I try to render this model it comes out rather flat. Using DirectX 9. Here's a couple of pictures so you see what I mean:
http://img36.imageshack.us/img36/6811/yawnm.jpg[^]
http://img36.imageshack.us/img36/8588/ugho.jpg[^]
The model is read out of a .3ds file and then I create a static buffer out of it, problem is that it always comes out like this. If I swap the y and z co-ords around I get a nice top down view of the model but with the same 2 dimensional qualities.
I know the 3ds file is fine and I'm sure its something simple that I'm missing. I just can't see it.
I've made and rendered static buffers before, and I'm pretty sure I never had this problem.
You can guarantee that I'll kick myself when I find out what the problem is.
Well, as it turns out the vertex data I was sending over to create the buffer had an extra 4 bytes for each vertex. This somehow managed to have the effect of making all of the X values 0. I knew it would be something stupid.
My current favourite word is: Delicious!
-SK Genius
Game Programming articles start - here[ ^]-
modified on Monday, May 25, 2009 5:45 PM
|
|
|
|
|
I'm not into Direct3D but from my OpenGL experience, enabling/defining light sources and/or normals?
"Republicans are the party that says government doesn't work and then they get elected and prove it." -- P.J. O'Rourke I'm a proud denizen of the Real Soapbox[ ^] ACCEPT NO SUBSTITUTES!!!
|
|
|
|
|
I think its about time we get a good thread on this.
I've searched the internets for this for some time now, and I have'nt been able to find a good, definitive thread on the creation of the perfect 3d body, so here goes.
I know there is a simple solution for this in the form of D3DX library, and its meshes that do the job for me completely, but thats not the point.
What i am building is a program for my graduation thesis that does not rely on this kind of help in an effort to gain a greater understanding of 3d graphics.
What i have come to understand is that the placement of the vertices is not a big deal, and a basic understanding of math for this is simple. Turns out, placing the vertices in the right order into the vertex buffer and the index buffer is a bit tricky, to say the least!
This is the general code for the placement of vertices in 3d space:
[pre]
int meridians; //
int parallels; //
for(float theta=0;theta < D3DX_PI ;theta = theta + D3DX_PI/meridians ){ //0-PI
for(float phi=0;phi < 2*D3DX_PI;phi= phi + 2*D3DX_PI/parallels){ //0-2PI
verts[index].x = cosf(theta)* sinf(phi);
verts[index].y = sinf(theta)* sinf(phi);
verts[index].z = cosf(phi);
}
}
</pre>
(and yes i know i use d3dx for PI, its not a biggie
So, some explanations for the index calculations or some references(in case i cant use the net) would be much appreciated, also the entire code would be awesome!
thanks.
|
|
|
|
|
You might read this paper by, Hugues Hoppe: Progressive Meshes[^]. He wrote much of the specification for the DirectX Mesh object,...his publications[^] are interesting as background.
The DirectX Mesh X File is convenient as a way to save the graphics object to an archived file format. As you undoubtedly know, displaying a sphere is done with a tessellation of triangular faces.
So, the obvious question is: what exactly characterizes the "perfect 3d body"? Clearly, there is alot to it besides the vertex configuration.
|
|
|
|
|
Thats an interesting read, allthough pretty advanced for my level of knowledge. I understand the basic principle of tesselation but my problem is currently based not on the creation of the vertices in 3d space but on acquiring the needed indexes to fill the index buffer, ill figure it out soon enough!
thanks
|
|
|
|
|
I see,...I initially thought this was more of a conceptual problem.
Here is a tutorial on using Index Buffers (it describes a cube, but, this is easier to visualize): DirectX Managed Index Buffer Tutorial[^]
That author has a series of beginning DirectX tutorials: Complete Listing of DirectX Tutorials[^]
Originally, I thought you were interested in the actual implementation of the basic C+++ code for displaying a 3D Object. There are a number of excellent books on the subject available, that explain the underlying details of the trigonometry, without using the DirectX library (and the associated dependency). If you can find "Tricks of the 3D Game Programming Gurus, Advanced 3D Graphics and Rasterization", by Andre LaMothe[^], or something comparable, I would buy it (it explains all the mathematics of 3D graphics Windows programming in a clear way).
In my research into graphics, I found the following gateways excellent and informative reading: Real-Time Rendering Resources[^], and, Tim Rowley's Listing of Siggraph Papers[^]
|
|
|
|
|
wow! thats alot of ground to cover! and this is what i am looking for!
Thanks alot, ill post the full code when i write it so other ppl can use it.
|
|
|
|
|
its finally done, if anyone needs it, here we go:
<pre>
class Sphere : public Entity
{
public:
IDirect3DVertexBuffer9* SphereVertexBuffer;
IDirect3DIndexBuffer9* SphereIndexBuffer;
int parallels;
int meridians;
float theta; // od 0 do pi
float phi; //od 0 to 2pi
int num_vertices;
int num_triangles;
void get_ime(){OutputDebugString("banana");};
Sphere(int *idd, std::string iime, int pparallels, int mmeridians, std::list<Entity*> *EEntity_list) : Entity(iime, *idd), parallels(pparallels), meridians(mmeridians){
float x,y,z;
theta=0; // od 0 do pi
phi=0;
int index=0;
num_vertices=2*(parallels-1)*(meridians)+2;
HR(gd3dDevice->CreateVertexBuffer(num_vertices* sizeof(VertexPos), D3DUSAGE_WRITEONLY,
0, D3DPOOL_MANAGED, &SphereVertexBuffer, 0));
VertexPos *v;
HR(SphereVertexBuffer->Lock( 0, 0, (void**)&v, 0 ))
for(int i=0;i<meridians;i++){ // iliti theta,manji kut
for(int j=0;j<2*parallels+1;j++){ // ili phi, veći kut od 0-2pi
if(j==0 || j == parallels ){
phi=phi+(D3DX_PI*2 / parallels)/2; //uvjeti za kapice
j++;
}
if(j==(parallels*2)) break;
x=cosf(theta)*sinf(phi);
if(fabs(x)<0.000001) x=0;
y=sinf(theta)*sinf(phi);
if(fabs(y)<0.000001) y=0;
z=cos(phi);
if(fabs(z)<0.000001) z=0;
v[index] = VertexPos(x,y,z);
index++;
phi=phi+(D3DX_PI*2 / parallels)/2;
}
phi=0;
theta=theta+(D3DX_PI/ meridians);
}
v[index]=VertexPos(0,0,1); //126 ako je 9, 9, a je//kapice iliti
index++;
v[index]=VertexPos(0,0,-1); //127
SphereVertexBuffer->Unlock();
//OutputDebugString(index);
HR(gd3dDevice->CreateIndexBuffer(12*meridians*(parallels-1) * sizeof(WORD), D3DUSAGE_WRITEONLY,
D3DFMT_INDEX16, D3DPOOL_MANAGED, &SphereIndexBuffer, 0));
WORD* k = 0;
int brojac=-1;
HR(SphereIndexBuffer->Lock(0, 0, (void**)&k, 0));
for(int i=1;i<meridians+1;i++){
k[++brojac]=num_vertices-2;
(i==meridians) ? (k[++brojac]=2*(parallels-1)-1):(k[++brojac]=i*2*(parallels-1)); //kapica gore, prednja
k[++brojac]=i*2*(parallels-1)-2*(parallels-1);
k[++brojac]=num_vertices-2;
(i==meridians) ? (k[++brojac]=0):(k[++brojac]=i*2*(parallels-1)+2*(parallels-1)-1); //kapica gore, preko puta
k[++brojac]=i*2*(parallels-1)-1;
for(int j=0;j<parallels-2;j++){
k[++brojac]=i*2*(parallels-1)-2*(parallels-1)+j;
(i==meridians) ? (k[++brojac]=2*(parallels-1)-j-1):(k[++brojac]=i*2*(parallels-1)+j); //prednji, lijevo gore trokut
k[++brojac]=i*2*(parallels-1)-2*(parallels-1)+j+1;
(i==meridians)?(k[++brojac]=2*(parallels-1)-j-1):(k[++brojac]=i*2*(parallels-1)+j); //prednji, suprotni
(i==meridians)?(k[++brojac]=2*(parallels-1)-j-2):(k[++brojac]=i*2*(parallels-1)+j+1);
k[++brojac]=i*2*(parallels-1)-2*(parallels-1)+j+1;
k[++brojac]=i*2*(parallels-1)-1-j;
(i==meridians)?(k[++brojac]=j):(k[++brojac]=i*2*(parallels-1)+2*(parallels-1)-1-j); //stražnji, lijevo gore trokut
k[++brojac]=i*2*(parallels-1)-2-j;
(i==meridians)?(k[++brojac]=j):(k[++brojac]=i*2*(parallels-1)+2*(parallels-1)-1-j);
(i==meridians)?(k[++brojac]=j+1):(k[++brojac]=i*2*(parallels-1)+2*(parallels-1)-2-j); //stražnji, suprotni
k[++brojac]=i*2*(parallels-1)-2-j;
}
k[++brojac]=num_vertices-1;
k[++brojac]=i*2*(parallels-1)-(parallels-1)-1; //kapica dolje, prednja
(i==meridians) ? (k[++brojac]=(parallels-1)):(k[++brojac]=i*2*(parallels-1)+(parallels-1)-1);
k[++brojac]=num_vertices-1;
k[++brojac]=i*2*(parallels-1)-(parallels-1); //kapica dolje, preko puta
(i==meridians) ? (k[++brojac]=(parallels-1)-1):(k[++brojac]=i*2*(parallels-1)+(parallels-1));
}
HR(SphereIndexBuffer->Unlock());
EEntity_list->push_back(this);
++(*idd); //*idd=*idd+1 <-isto kao i navedeno
}
void Render(){
HR(gd3dDevice->SetStreamSource(0, SphereVertexBuffer, 0, sizeof(VertexPos)));
HR(gd3dDevice->SetIndices(SphereIndexBuffer));
HR(gd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST,0,0,num_vertices,0,4*meridians*(parallels-1)));
//HR(gd3dDevice->DrawPrimitive(D3DPT_POINTLIST,0,144));
//HR(gd3dDevice->DrawIndexedPrimitive( D3DPT_POINTLIST,0,0,200,0,288));
}
};
</pre>
|
|
|
|
|
I was looking for something like this. Awesome. Thanks for all the hard work
|
|
|
|
|
im glad i could be helpful
|
|
|
|
|
I have read the solution to the issue and I was also in the process of learning how to make 3D's. I checked the code and will be trying this one out. I hope you don't mind. Thanks a lot!
|
|
|
|
|
ofcourse i dont mind, ima glad.
By the way there are a few limitations you need to be aware of.
First the smallest values for meridians and parallels are 2 both, which makes sense since its not possible to draw a sphere any simpler than that. With 2,2 values, you get a double tetrahedron. The max values are about 180, 180, which makes a pretty detailed sphere, and ALOT of triangles, so it cripples the framerate. This is due to float precision, it can be solved in certain ways, but i doubt you will need a sphere that detailed.
Anyway, have fun.
|
|
|
|
|
hello,
i'm new to openGL, and i'm trying to build a color lookup table of size 265
is there any thing wrong in my code??
// i define the array in header
GLfloat color_table[256][4];
void BuildColorLookUpTable()
{
for(INT i = 0; i < 256; i++)
{
GLfloat red=i/255;
GLfloat green=0;
GLfloat blue=1-i/255;
color_table[i][0] = 0;
color_table[i][0] = red;
color_table[i][0] = green;
color_table[i][0] = blue;
glutSetColor(i, red, green, blue);
}
}
also, can anyone pls give me some guides
thanks
|
|
|
|
|
How is your code acting versus what you expected?
Also, you might ask yourself what i/255 computes to?
"Republicans are the party that says government doesn't work and then they get elected and prove it." -- P.J. O'Rourke I'm a proud denizen of the Real Soapbox[ ^] ACCEPT NO SUBSTITUTES!!!
|
|
|
|
|