Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

Shawn619

Member Since 17 Mar 2012
Offline Last Active May 22 2013 08:55 PM
-----

Topics I've Started

Polished Model Viewer

05 May 2013 - 02:34 AM

I made this 3d model viewer almost out of necessity, because ShaderDesigner and RenderMonkey weren't fulfilling my needs. I hope you all enjoy it.

Features:
(i)Free-flying camera (WASD controls)
(ii)Rotating Light
(iii)GLSL(Vertex and Fragment) shading
(iv)Grid-style environment
(v)720x480 resolution
(vi)Scale and rotate model
(vii)Custom, hand-written GUI
(viii)Import models(.3DS) (*Only use .3DS files exported through 3ds Max)
(ix)Lightweight

Restrictions:
(i)No textures
(ii)No more than 1 light supported
(iii)Only static models
(iv)Must hardcode light and material values in shader

 

 

Can be downloaded off my website-> http://www.polishedgames.com/PMV.zip *Also, I wrote example shaders and model so you may test for yourself


Basic texture render

04 May 2013 - 09:52 AM

I want a texture across my entire window, but i'm getting some funky results.

 

Also, I'm using http://www.videotutorialsrock.com/opengl_tutorial/textures/text.php .bmp loader

 

This is my display callback function:

void drawOrtho2Scene() {
 
glClear(GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, windowWidth, windowHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glOrtho(0.0f, windowWidth, 0.0f, windowHeight, 0.0f, 1.0f);
 
 
//enables/disables
glDisable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
 
 
//bind texture
glBindTexture(GL_TEXTURE_2D, aboutTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 
glColor3f(1.0f, 1.0f, 1.0f);
 
 
//draw about screen
glBegin(GL_QUADS); 
glTexCoord2f( 0.0f, 0.0f );glVertex2f(0, 0); 
 
//top-left
glTexCoord2f( 1.0f, 0.0f );glVertex2f(windowWidth, 0); 
 
//top-right
glTexCoord2f( 1.0f, 1.0f );glVertex2f(windowWidth, windowHeight); 
 
//bottom-right
glTexCoord2f( 0.0f, 1.0f );glVertex2f(0, windowHeight); 
 
//bottom-left
glEnd();
 
 
//enables/disables
glDisable(GL_TEXTURE_2D);
 
glutSwapBuffers();
}

 

This is the original image:

20iz5hf.jpg

 

This is how it displays it:

xppxkg.jpg


Lock window size

01 May 2013 - 05:06 PM

A couple questions about window sizes in OpenGL and GLUT:

(1) How can i lock a window at 720x480 OR fullscreen(windowed)? (ie: take over manual resize and only have maximize/minimize)

(2) How can i lock a window at 720x480? (take away resize AND maximize button)

(3) How can i lock a window at fullscreen(windowed)?


3D draw colors bleed into 2D draw colors

29 April 2013 - 07:49 PM

When I draw things in 3D perspective, which contains green lighting, it bleeds into my 2D ortho drawings.

 

In this picture, I draw my 3d scene on the large left-side viewport, and draw my 2d scene on the smaller right-side viewport(which contains a 2d red triangle):

 

(you can see the full red triangle has been tainted with green colors from previous 3d drawings)

 

2mgtwci.jpg

 

This is my drawing structure:

//start 3d drawing
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, windowWidth/1.3, windowHeight);
glClearColor(0,0.5,0.5,0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, (float)windowWidth / (float)windowHeight, 0.4, 9000.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
 
//draw 3d primitives + model and view transforms
 
//2D drawing
glClear(GL_DEPTH_BUFFER_BIT);
glViewport(windowWidth/1.3, 0, windowWidth, windowHeight);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0f, windowWidth, windowHeight, 0.0f, 0.0f, 1.0f);
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glDisable(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
 
//draw red triangle
glPushMatrix();
    glColor3f(1.0f, 0.0f, 0.0f);
    glBegin(GL_TRIANGLES); 
        glVertex3f(0.0f, 0.0f, 0.0f); 
        glVertex3f(20.0f, 20.0f, 0.0f);
        glVertex3f(70.0f, 20.0f, 0.0f);
    glEnd(); 
glPopMatrix();
 
//swap buffers
glutSwapBuffers();
 

Attenuation shader, correct or not correct?

27 April 2013 - 07:26 PM

Is this the correct way of calculating and applying attenuation?

 

This is my basic diffuse shader with attenuation:

 

.vert

varying vec3 vertex_light_position;

varying vec3 vertex_light_half_vector;

varying vec4 color;

varying vec3 N;

varying vec3 v;
 void main(void)

{

    v = vec3(gl_ModelViewMatrix * gl_Vertex);

    N = normalize(gl_NormalMatrix * gl_Normal);
    color = gl_Color;

    vertex_light_position = normalize(gl_LightSource[0].position.xyz);
    vertex_light_half_vector = normalize(gl_LightSource[0].halfVector.xyz);



    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;

}

 

.frag

varying vec3 vertex_light_position;

varying vec3 vertex_light_half_vector;

varying vec4 color;

varying vec3 N;

varying vec3 v;
void main()

{ 

   float constantAttenuation=1.0;

   float linearAttenuation=1.0;

   float quadraticAttenuation=0.02;
   float dist = length(gl_LightSource[0].position - v);

   float att = 1.0/(constantAttenuation + (linearAttenuation * dist) + (quadraticAttenuation * dist * dist));


   vec3 L = normalize(gl_LightSource[0].position.xyz - v);

   vec3 E = normalize(-v);

   vec3 R = normalize(reflect(-L,N));

  

   vec4 diffuse_color = vec4(0.0,1.0,0.0,0.0);

   float diffuse_value = max(dot(N,L), 0.0);

  

   if (gl_FrontFacing){

       gl_FragColor = color + (((diffuse_color-color) * (diffuse_value))*att);

   }else{

       gl_FragColor = color;

   }

  

}

PARTNERS